datatemplate

WPF - DataTemplate to show only one hierarchical level in recursive data

Hi all, I am using a tree to display my data: persons grouped by their teams. In my model a team can contain another team, so the recursion. I want do display details about the selected node of the tree using a contentpresenter. If the selection is a person, everything is fine: I can show the person name or datails without problem using...

Why can't I find DataTemplates in merged resource dictionaries?

In my MainWindow.xaml, I have the following reference to a ResourceDictionary: <Window.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="MainSkin.xaml" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Window.Resources> In MainSkin....

Set Window Properties based on Datatype of UserControl

I've got a simple window, that is container for various views. I've got a DataTemplate that shows the correct view based on whatever the window's MainViewModel property is set to. <DataTemplate DataType="{x:Type VM:StartupViewModel}"> <AdornerDecorator> <V:StartupView /> </AdornerDecorator> </DataTemplate> What I'd li...

Silverlight 3.0 Custom ListBox DataTemplate has a checkbox, checked event not firing

The datatemplate for the ListBox is set dynamically by XamlReader.Load. I am subscribing to Checked event by getting the CheckBox object using VisualTreeHelper.GetChild. This event is not getting fired Code Snippet public void SetListBox() { lstBox.ItemTemplate = XamlReader.Load(@"<DataTemplate xmlns='http://sch...

Getting the SelectedItem from a combobox in a DataTemplate

Lets say I've got a DataTemplate like so <DataTemplate x:Key="Body"> <StackPanel Orientation="Horizontal"> <ComboBox ItemsSource="{Binding Path=Person.Children}"></ComboBox> <Button Click="Button_Click">Hello</Button> </StackPanel> </DataTemplate> Which shows a list of ComboBoxes followed by a button. Now, on clicki...

Is it possible to template a template in WPF XAML?

Is it possible to use templates within templates? For instance, I have the following two templates: <HierarchicalDataTemplate x:Key="RecursiveTemplate" ItemsSource="{Binding Children}"> <StackPanel Margin="1" Orientation="Horizontal"> <Ellipse Fill="DarkGreen" Width="14" Height="14"/> <TextBlock ...

Pass view to viewmodel with datatemplate

I have a window named ParameterEditorView with a ParameterEditorViewModel as DataContext. In the ParameterEditorViewModel I have a list of ParameterViewModel. In the ParameterEditorView I have an ItemsControl whose ItemsSource is binded to the list of ParameterViewModel in the ParameterEditorViewModel. I need the ParameterViewModel to ha...

How do you compose DataTemplates / link to a child datatemplate in WPF?

Here's the problem. Given a large/intricate datatemplate A, which has 3 sections - General, Properties, Misc. Imagine 3 grids for each. Now I need to reuse the Properties section of the above Datatemplate in another place. Reasons: To avoid redundancy + ensure that further updates to the datatemplate are applied identically to all usages...

WPF: How to dynamically find a usercontrol or datatemplate

I have a bunch of datatemplates I use to display various sql-views in an ItemsControl. I don't know which datatemplate i'm going to use until run-time. (every view has different columns) Next to that, I made a generic dynamic datatemplate for all those views that don't need anything special. When I display the view I want to first look ...

How can I refer to a binding converter in another namespace in Silverlight XAML?

Since you apparently can't create a Silverlight DataTemplate in C#, I'm trying to create one in XAML. I have a converter that I need to refer to, that I have defined in C# in another namespace. I've tried doing this: <UserControl.Resources> <DataTemplate x:Key="PriceTemplate"> <TextBlock Text="{Binding Price, Convert...

WPF - Binding a color resource to the data object within a DataTemplate

I have a DataTemplate and a SolidColorBrush in the DataTemplate.Resources section. I want to bind the color to a property of the same data object that the DataTemplate itself is bound to. However, this does not work. The brush is ignored. Why? Here is the simplified code: <DataTemplate DataType="{x:Type data:MyData}" x:Name="dt...

Simple Binding question, unable to bind to button command in a DataTemplate using MVVM Light Toolkit

I've been attempting to bind to buttons within a DataTemplate without much success. The button does not fire. Button Click works successfully outside of the DataTemplate. Yet if I create a Click="button_click" the click button is fired. The Button Content binds perfectly as well. Example to illustrate.. ...

Binding Data Template element to property on sub-class

Hi guys, I have a class, for experiment sake call it foo() and another class, call it bar() I have a data template for class foo() defined in my xaml, but one of foo()'s properties is a bar() object such that foo() { Public string Name {get; set;} Public int ID {get; set;} Public bar barProp {get; set;} } and bar() ...

Setting CommandTarget to selected control in a TabControl

I have a WPF window with a few buttons and a tabcontrol having a tab for each 'document' the user is working on. The tabcontrol uses a DataTemplate to render the data in ItemSource of the tabcontrol. The question: If one of the buttons is clicked, the command should be executed on the control rendering the document in the active tab, b...

How to access data from another datatemplate in wpf ?

Hi, 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:Na...

How to Access a Control present inside a DataTemplate

Hi, I have Few TextBlock inside the Data template as follow: <DataTemplate> <StackPanel x:Name="stackPanelItems" Orientation="Horizontal"> <TextBlock x:Name="myTextBox" HorizontalAlignment="Center" VerticalAlignment="Top" FontSize="14" /> </StackPanel> </DataTemplate> Now we need to Make the myTextBox Collsapsed...

How can I find any control in the ItemTemplate of a TabControl?

Hi, I have a TabControl <TabControl Name="myTabControl" IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding}"> <TabControl.ItemTemplate> <DataTemplate> <DockPanel Width="120"> <Button Na...

MVVM with animations (should I use VisualStateManager?)

I've got a View.xaml with the following set in Resources-section: <DataTemplate DataType="{x:Type ViewModels:MyFirstViewModel}"> <Views:MyFirstView Content="{Binding}" /> </DataTemplate> <DataTemplate DataType="{x:Type ViewModels:MySecondViewModel}"> <Views:MySecondView Content="{Binding}"/> </DataTemplate> In the content of ...

WPF Accessing Items inside Listbox which has a UserControl as ItemTemplate

I have Window that has a ListBox ListBox(MyListBox) has a DataTable for its DataContext ListBox's ItemSource is : {Binding} Listbox has a UserControl(MyUserControl) as DataTemplate UserControl has RadioButtons and TextBoxes (At first They're filled with values from DataTable and then user can change them) Window has one Submit Button ...

What am I doing wrong with my ItemsControl & databinding?

I'm reworking my simple hex editor to practice using what I've recently learned about data binding in WPF. I'm not sure what I'm doing wrong here. As I understand it, for each byte in the collection "backend" (inherits from ObservableCollection), my ItemsControl should apply the DataTemplate under resources. This template is just a text...