EN
Este conteúdo não está disponível em seu idioma, mas aqui está a versão em inglês.

DataTemplateSelector class

Applies to Windows and Windows Phone

Enables custom template selection logic at the application level.

Inheritance

Object
  DataTemplateSelector

Syntax


public class DataTemplateSelector


See Remarks

Attributes

[MarshalingBehavior(Agile)]
[Threading(Both)]
[Version(0x06020000)]
[WebHostHidden()]

Members

The DataTemplateSelector class has these types of members:

Constructors

The DataTemplateSelector class has these constructors.

ConstructorDescription
DataTemplateSelector Initializes a new instance of the DataTemplateSelector class.

 

Methods

The DataTemplateSelector class has these methods. It also inherits methods from the Object class.

MethodDescription
SelectTemplate(Object) Returns a specific DataTemplate for a given item.
SelectTemplate(Object, DependencyObject) Returns a specific DataTemplate for a given item and container.
SelectTemplateCore(Object) When implemented by a derived class, returns a specific DataTemplate for a given item or container.
SelectTemplateCore(Object, DependencyObject) When implemented by a derived class, returns a specific DataTemplate for a given item or container.

 

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 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.

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.

Requirements

Minimum supported client

Windows 8 [Windows Store apps only]

Minimum supported server

Windows Server 2012 [Windows Store apps only]

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]

Namespace

Windows.UI.Xaml.Controls
Windows::UI::Xaml::Controls [C++]

Metadata

Windows.winmd

See also

ItemTemplateSelector
DataTemplate
ContentControl.ContentTemplateSelector
GroupStyle.HeaderTemplateSelector
ItemsControl.ItemsTemplateSelector
How to group items in a list or grid
Adding ListView and GridView controls

 

 

Mostrar:
© 2014 Microsoft