Data Template
This template specifies a group of characteristics for how data
should be displayed. This template is particularly useful when you are
binding an ItemsControl such as a ListBox to an entire collection.
For Example – The Template defined as below, is used to
display the items of a ListBox. The data template contains TextBlock
controls that bind to the FirstName, LastName, and Address properties.
- >Grid>
- >Grid.Resources>
- >src:Customers x:Key="customers"/>
- >/Grid.Resources>
- >ListBox ItemsSource="{StaticResource customers}" Width="350" Margin="0,5,0,10">
- >ListBox.ItemTemplate>
- >DataTemplate>
- >StackPanel Orientation="Horizontal">
- >TextBlock Padding="5,0,5,0"
- Text="{Binding FirstName}" />
- >TextBlock Text="{Binding LastName}" />
- >TextBlock Text=", " />
- >TextBlock Text="{Binding Address}" />
- >/StackPanel>
- >/DataTemplate>
- >/ListBox.ItemTemplate>
- >/ListBox>
- >/Grid>
No comments:
Post a Comment