datatemplate

WPF TabControl and DataTemplates

你离开我真会死。 提交于 2019-12-20 10:08:14
问题 I've got a set of ViewModels that I'm binding to the ItemsSource property of a TabControl. Let's call those ViewModels AViewModel, BViewModel, and CViewModel. Each one of those needs to have a different ItemTemplate (for the header; because they each need to show a different icon) and a different ContentTemplate (because they have very different interaction models). What I'd like is something like this: Defined in Resource.xaml files somewhere: <DataTemplate x:Key="ItemTemplate" DataType="{x

How to access data from another datatemplate in wpf?

旧巷老猫 提交于 2019-12-20 06:37:21
问题 I have 2 Datatemplates. One contain a grid , second one contain a button. I need to send command parameters of button as selected grid items. How can i do this ? <ObjectDataProvider x:Key="Datas" ObjectType="{x:Type ViewModel:UserControlViewModel}"></ObjectDataProvider> <DataTemplate x:Key="SourceGrid"> <WPFToolKit:DataGrid x:Name="SourceDataGrid" ItemsSource="{Binding Source={StaticResource Datas},Path=SourceGridData}" CanUserSortColumns="True" GridLinesVisibility="None"

How to programmatically bind a (dependency) property of a control that's inside a DataTemplate?

别等时光非礼了梦想. 提交于 2019-12-20 04:12:23
问题 The TextBlock resides in a DataTemplate , thus I can't refer to it by its name. So how do I bind its (e.g.) Text property programmatically? XAML: <UserControl x:Class="MyNameSpace.MyCustomControl" ... > ... <ListBox ItemsSource="{Binding Path=ItemsSource}"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <TextBlock/> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox> ... </UserControl> Code: public partial class MyCustomControl : UserControl { ...

DataTemplates and generic types

三世轮回 提交于 2019-12-20 03:49:09
问题 I have a generic class public abstract class BaseViewModel<T> Since I am trying to create a DataTemplate that will be applied to all classes that derive from BaseViewModel, I set the type to BaseViewModel: <DataTemplate DataType="{x:Type vm:BaseViewModel}"> However, this does not work since it looks like xaml does not support generic data types. Are there any work arounds to this? 回答1: I would create a non-generic version of BaseViewModel and let the generic one inherit from it: public

How to propagate styles to Hyperlinks inside a DataTemplate?

时光毁灭记忆、已成空白 提交于 2019-12-19 17:41:57
问题 I'm try to set the Foreground colour on a Hyperlink using a Style object in an ancestor's Resources , but it's not having any effect. I even used the BasedOn tip from Changing Hyperlink foreground without losing hover color, but it's not made any difference - I still get a blue hyperlink that is red on hover. Here's the XAML for my controls, including an ItemsControl whose items are shown using a hyperlink: <StackPanel Background="Red" TextElement.Foreground="White"> <StackPanel.Resources>

How to use both Command and EventTrigger in DataTemplate Button?

你离开我真会死。 提交于 2019-12-19 09:55:57
问题 I have a Button in a DataTemplate that is bound to a Command in my ViewModel. The button also has an EventTrigger that kicks off a Storyboard that hides the edit controls (of which the button is a part.) The Storyboard works fine if I pick up the PreviewMouseDown event, but the Command never gets called. If I pick up the MouseDown event in my EventTrigger, the Command works, but the Storyboard doesn't execute. How can I get both the Command and the Storyboard to execute when the button is

WPF - ItemTemplate not acting as expected

天大地大妈咪最大 提交于 2019-12-19 09:05:39
问题 I have a UserControl which I'm using to display a list of UIElement s. The control consists of a single ItemsControl with it's ItemPanelTemplate switched for a horizontal StackPanel , its ItemsSource bound to a DependencyProperty exposed by the UserControl and its ItemTemplate set in the UserControl.Resources . Everything works fine except the ItemTemplate never get's applied and I can't see why. The full source is below. UserControl.xaml - <UserControl x:Name="UC" x:FieldModifier="private" x

How to set the the zindex of datatemplate's in a longlistselector

徘徊边缘 提交于 2019-12-19 07:18:08
问题 I have a longlistselector with certain images that i add in this longlistselector. I also change the margins of this image to make the image go up or down and so on. But i want to put this image infront of another image in this longlistselector. I have tried using Canvas.Zindex. I have tried setting it at the grid level, at image level and at the top level of of the longlistselector.() But it still doesn't work. Does anybody have some idea's? You can find my code bellow: <phone

WPF: TextBox Text is not updating

蓝咒 提交于 2019-12-19 06:14:12
问题 I have a user control that i am using inside a DataTemplate , this UserControl contains a TextBox which is binded with Value property(declared as a DependencyProperty ) of my UserControl . In data template I bind this Value property with my actual property say Name (also a DependencyProperty ). It works properly, I assign a value to Name property while loading and my TextBox displays it, i change the value from TextBox and it updates my Name property also. Now the problem comes while I add a

WPF: TextBox Text is not updating

梦想的初衷 提交于 2019-12-19 06:14:01
问题 I have a user control that i am using inside a DataTemplate , this UserControl contains a TextBox which is binded with Value property(declared as a DependencyProperty ) of my UserControl . In data template I bind this Value property with my actual property say Name (also a DependencyProperty ). It works properly, I assign a value to Name property while loading and my TextBox displays it, i change the value from TextBox and it updates my Name property also. Now the problem comes while I add a