Skip to content

Latest commit

 

History

History
43 lines (27 loc) · 2.86 KB

datatemplateselector.md

File metadata and controls

43 lines (27 loc) · 2.86 KB
-api-id -api-type
T:Windows.UI.Xaml.Controls.DataTemplateSelector
winrt class

Windows.UI.Xaml.Controls.DataTemplateSelector

-description

Enables custom template selection logic at the application level.

-xaml-syntax

See Remarks

-remarks

For more info about data templates, see the DataTemplate class and Item containers and templates.

The base DataTemplateSelector class is not used as an object element in XAML. However, it is a common scenario to derive a custom DataTemplateSelector, map an xmlns prefix for the custom class and its namespace/assembly, and then refer to an instance of the custom class as defined in a Resources block in XAML. This makes it possible to refer to the custom template selector class by x:Key, and use that reference to set the value of properties such as ItemTemplateSelector in XAML templates and visual states.

The callable methods of DataTemplateSelector are the two SelectTemplate overloads. The overridable methods of DataTemplateSelector are the two SelectTemplateCore overloads. To define an effective DataTemplateSelector subclass, provide implementations for SelectTemplateCore(Object) and SelectTemplateCore(Object, DependencyObject). All these methods return a DataTemplate instance that's typically a specific choice that's appropriate for the inputs of the method that was called to obtain it.

App code typically doesn't call SelectTemplate methods; the methods exists so that the infrastructure can call it while choosing the correct templates based on using a DataTemplateSelector instance from a property value such as ItemsControl.ItemsTemplateSelector.

Version history

Windows version SDK version Value added
1809 17763 GetElement
1809 17763 RecycleElement

-examples

-see-also

ItemTemplateSelector, DataTemplate, ContentControl.ContentTemplateSelector, GroupStyle.HeaderTemplateSelector