Gets or sets the custom logic for choosing a template used to display each item.
Assembly: PresentationFramework (in PresentationFramework.dll)
You use the ItemTemplate to specify the visualization of the data objects. If you have more than one template defined and want to supply logic to return a template to use, then you use this property. Note that this property is ignored if ItemTemplate is set.
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, or DynamicResource. Unless the styles themselves contain references to potential run-time references such as system resources or user preferences, StaticResource reference to a style is usually recommended for performance.
x:Key string value referring to the selector being requested as a resource.
Legacy Code Example
In the following example, the auctionItemDataTemplateSelector resource name (corresponding to an AuctionItemDataTemplateSelector class) is assigned to the property of the ItemsControl.Code snippet is not found. Confirm that the code snippet name 'DataTemplateSelector' is correct.
The following example shows the implementation of the AuctionItemDataTemplateSelector class with an override of the SelectTemplatemethod:Code snippet is not found. Confirm that the code snippet name 'DataTemplateSelector' is correct.
In this case, within the SelectTemplate method of the class, there is logic to return the appropriate template based on the value of the SpecialFeatures property of the item object passed. The template to return is found in the resources of the enveloping Window element.
When you set the ItemsControl is directed to automatically call the SelectTemplate method of AuctionItemDataTemplateSelector for each of the items in the collection to which the ItemsControl is bound. The call passes the data item as an object. The DataTemplate that is returned by the method is then used to display that data item.property, the
For another example, see Data Templating Overview.
Available since 3.0