DataTemplateSelector DataTemplateSelector DataTemplateSelector Class

Enables custom template selection logic at the application level.

Syntax

Declaration

public class DataTemplateSelectorpublic class DataTemplateSelectorPublic Class DataTemplateSelector
See Remarks

Remarks

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 a 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(System.Object,Windows.UI.Xaml.DependencyObject) 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(System.Object,Windows.UI.Xaml.DependencyObject) 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 ItemTemplateSelector.

For example XAML that references a custom DataTemplateSelector as the HeaderTemplateSelector value, and example code that shows the overrides for HeaderTemplateSelector methods, see How to group items in a list or grid.

Constructors summary

Initializes a new instance of the DataTemplateSelector class.

Methods summary

Returns a specific DataTemplate for a given item.

Returns a specific DataTemplate for a given item and container.

Constructors

  • DataTemplateSelector()
    DataTemplateSelector()
    DataTemplateSelector()
    DataTemplateSelector()

    Initializes a new instance of the DataTemplateSelector class.

    public DataTemplateSelector()public DataTemplateSelector()Public Function DataTemplateSelector() As

Methods

  • SelectTemplate(System.Object)
    SelectTemplate(System.Object)
    SelectTemplate(System.Object)
    SelectTemplate(System.Object)

    Returns a specific DataTemplate for a given item.

    public DataTemplate SelectTemplate(System.Object)public DataTemplate SelectTemplate(System.Object)Public Function SelectTemplate(System.Object) As DataTemplate

    Parameters

    • item
      System.Object
      System.Object
      System.Object

      The item to return a template for.

    Returns

  • SelectTemplate(System.Object,Windows.UI.Xaml.DependencyObject)
    SelectTemplate(System.Object,Windows.UI.Xaml.DependencyObject)
    SelectTemplate(System.Object,Windows.UI.Xaml.DependencyObject)
    SelectTemplate(System.Object,Windows.UI.Xaml.DependencyObject)

    Returns a specific DataTemplate for a given item and container.

    public DataTemplate SelectTemplate(System.Object,Windows.UI.Xaml.DependencyObject)public DataTemplate SelectTemplate(System.Object,Windows.UI.Xaml.DependencyObject)Public Function SelectTemplate(System.Object,Windows.UI.Xaml.DependencyObject) As DataTemplate

    Parameters

    Returns

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Attributes

Windows.Foundation.Metadata.ComposableAttribute
Windows.Foundation.Metadata.ThreadingAttribute
Windows.Foundation.Metadata.WebHostHiddenAttribute
Windows.Foundation.Metadata.MarshalingBehaviorAttribute
Windows.Foundation.Metadata.ContractVersionAttribute

Details

Assembly

Windows.UI.Xaml.Controls.dll