GridViewColumn.CellTemplate Property

 

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

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

Public Property CellTemplate As DataTemplate

Property Value

Type: System.Windows.DataTemplate

A DataTemplate that is used to format a column cell. 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 CellTemplate="{ResourceExtension TemplateResourceKey}"/>

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.

System_CAPS_noteNote

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

Identifier field

CellTemplateProperty

Metadata properties set to true

None

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

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

.NET Framework
Available since 3.0
Return to top
Show: