Gets or sets a template selector that enables an application writer to provide custom template-selection logic.
Assembly: PresentationFramework (in PresentationFramework.dll)
Typically, you create a DataTemplateSelector when you have more than one DataTemplate for the same type of objects and you want to supply your own logic to choose a DataTemplate to apply based on the properties of each data object. Note that if you have objects of different types you can set the DataType property on the DataTemplate. If you do that, then there is no need to create a DataTemplateSelector. Furthermore, if you have objects of the same type but with different properties, you can also consider using a DataTrigger or a data converter. For more information, see Data Templating Overview.
To create a template selector, create a class that inherits from DataTemplateSelector and override the SelectTemplate method. After your class is defined, you can assign an instance of the class to the template selector property of your element.
If both the ContentTemplate properties are set, then this property is ignored.and the
The following example shows how to use the ComboBox to the Content property of a Label, which inherits from ContentControl. When the user selects a value below 5, the value of the selected item appears in a black square in the Label. When the user selects a value that is 5 or above, the value appears in a green ellipse. The example accomplishes this by creating two DataTemplate objects and a DataTemplateSelector, which is set to the property and chooses the appropriate DataTemplate based on the value of the selected item.property. This example binds the selected item in a
Available since 3.0