Questions tagged [datatemplate]

Data templating is a feature of WPF and Xamarin.Forms that lets you customize the presentation of data.

Data templating is a feature of WPF and Xamarin.Forms that lets you customize the presentation of data. It is typically used by setting the ContentTemplate of a ContentControl.

Introduction on Microsoft Docs: Data Templating Overview

The example below use a DataTemplate to define the data presentation in a ListBoxItem, by a Panel with 3 TextBlocks.

<ListBox Width="400" Margin="10"
         ItemsSource="{Binding Source={StaticResource myTodoList}}">
   <ListBox.ItemTemplate>
     <DataTemplate>
       <StackPanel>
         <TextBlock Text="{Binding Path=TaskName}" />
         <TextBlock Text="{Binding Path=Description}"/>
         <TextBlock Text="{Binding Path=Priority}"/>
       </StackPanel>
     </DataTemplate>
   </ListBox.ItemTemplate>
 </ListBox>
2487 questions
227
votes
7 answers

Difference between Control Template and DataTemplate in WPF

What is difference between a ControlTemplate and a DataTemplate in WPF?
Firoz
  • 7,224
  • 10
  • 41
  • 56
124
votes
7 answers

Access parent DataContext from DataTemplate

I have a ListBox which binds to a child collection on a ViewModel. The listbox items are styled in a DataTemplate based on a property on the parent ViewModel: