CellTemplateSelector Property

GridViewColumn.CellTemplateSelector Property

 

Gets or sets a DataTemplateSelector that determines the template to use to display cells in a column.

Namespace:   System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)

public DataTemplateSelector CellTemplateSelector { get; set; }

Property Value

Type: System.Windows.Controls.DataTemplateSelector

A DataTemplateSelector that provides DataTemplate selection for column cells. The default is null.

The following properties all bind to and display the content of a column cell, and are listed here in their order of precedence, from highest to lowest:

<object CellTemplateSelector="{ResourceExtension DataTemplateSelectorClassKey}"/>

<object>
  <object.CellTemplateSelector>
    <MyDataTemplateSelectorImplementation .../>
  </object.CellTemplateSelector>
</object>

MyDataTemplateSelectorImplementation

A class derived from DataTemplateSelector that implements a practical SelectTemplate override. For information about how to map your custom class, see XAML Namespaces and Namespace Mapping for WPF XAML.

ResourceExtension

One of the following: StaticResource, or DynamicResource. See XAML Resources.

DataTemplateSelectorClassKey

The key that identifies the selector implementation being requested. The key refers to a derived class that implements a practical SelectTemplate override. For information about how to map your custom class, see XAML Namespaces and Namespace Mapping for WPF XAML. You can also programmatically add an instance of your DataTemplateSelector class as a resource to a resource dictionary.

Identifier field

CellTemplateSelectorProperty

Metadata properties set to true

None

The following example shows how to set the CellTemplateSelector property.


<ListView ItemsSource="{Binding Source={StaticResource EmployeeData}, 
                                        XPath=Employee}">
  <ListView.View>       
    <GridView>
      <GridViewColumn Header="First Name"
               DisplayMemberBinding="{Binding XPath=FirstName}" />
      <GridViewColumn Header="Last Name"  
               CellTemplate="{StaticResource LastNameCellTemplate}"/>
      <GridViewColumn Header="Favorite City" 
               CellTemplateSelector="{DynamicResource 
                                      FavoriteCityTemplateSelector}"/>
    </GridView>
  </ListView.View>    
</ListView>

.NET Framework
Available since 3.0
Return to top
Show:
© 2016 Microsoft