GridViewColumn.CellTemplate Property

Definition

Gets or sets the template to use to display the contents of a column cell.

C#
public System.Windows.DataTemplate CellTemplate { get; set; }

Property Value

A DataTemplate that is used to format a column cell. The default is null.

Examples

The following example shows how to specify a DataTemplate to use to display a GridViewColumn.

XAML
<DataTemplate x:Key="myCellTemplateMonth">
  <DockPanel>
    <TextBlock Foreground="DarkBlue" HorizontalAlignment="Center">
      <TextBlock.Text>
        <Binding Path="Month"/>
      </TextBlock.Text>
    </TextBlock>
  </DockPanel>
</DataTemplate>
XAML
<GridViewColumn Header="Month" Width="80"
      CellTemplate="{StaticResource myCellTemplateMonth}"/>

Remarks

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:

XAML Attribute Usage

<object CellTemplate="{ResourceExtension TemplateResourceKey}"/>

XAML Property Element Usage

XAML Values

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

TemplateResourceKey The key that identifies the template being requested. The key refers to an existing resource in a ResourceDictionary.

Note

Property element syntax is technically possible, but not recommended. See Inline Styles and Templates. A binding reference using or is also possible, but uncommon.

Dependency Property Information

Item Value
Identifier field CellTemplateProperty
Metadata properties set to true None

Applies to

Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

See also