Gets or sets the DataTemplate used to display each item.
Assembly: PresentationFramework (in PresentationFramework.dll)
You use the ItemsControl is bound to a collection object and you do not provide specific display instructions using a DataTemplate, the resulting UI of each item is a string representation of each object in the underlying collection.to specify the visualization of the data objects. If your
During content generation, the ItemsPanel initiates a request for the ItemContainerGenerator to create a container for each data item. For ListBox, the container is a ListBoxItem. The generator calls back into the ItemsControl to prepare the container.
Similar to all ContentControl types, the ControlTemplate of a ListBoxItem contains a ContentPresenter. When the template is applied, it creates a ContentPresenter whose ContentTemplate is bound to the ContentTemplate of the ListBoxItem.
The ItemsControl provides great flexibility for visual customization and provides many styling and templating properties. Use the ItemContainerStyle property or the ItemContainerStyleSelector property to set a style to affect the appearance of the elements that contain the data items. For example, for ListBox, the generated containers are ListBoxItem controls; for ComboBox, they are ComboBoxItem controls. To affect the layout of the items, use the ItemsPanel property. If you are using grouping on your control, you can use the GroupStyle or GroupStyleSelector property.
For more information, see Data Templating Overview.
One of the following: StaticResource Markup Extension, or DynamicResource Markup Extension. Unless the styles themselves contain references to potential run-time references such as system resources or user preferences, StaticResource Markup Extension reference to a style is usually recommended for performance.
x:Key Directive string value referring to the template being requested as a resource.
The following example shows how to create a DataTemplate inline. The DataTemplate specifies that each data item appears as three TextBlock elements within a StackPanel. In this example, the data object is a class called Task. Note that each TextBlock element in this template is bound to a property of the Task class.
It is more common to define a DataTemplate in the resources section so it can be a reusable object, as in the following example:
Now you can use myTaskTemplate as a resource, as in the following example:
For the complete sample, see Introduction to Data Templating Sample.
Available since 3.0
Available since 2.0
Windows Phone Silverlight
Available since 7.0