.NET Framework Class Library
GridViewColumn..::.CellTemplate Property

Updated: July 2009

Gets or sets the template to use to display the contents of a column cell. This is a dependency property.

Namespace:  System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
Syntax

Visual Basic (Declaration)
Public Property CellTemplate As DataTemplate
Visual Basic (Usage)
Dim instance As GridViewColumn
Dim value As DataTemplate

value = instance.CellTemplate

instance.CellTemplate = value
C#
public DataTemplate CellTemplate { get; set; }
Visual C++
public:
property DataTemplate^ CellTemplate {
    DataTemplate^ get ();
    void set (DataTemplate^ value);
}
JScript
public function get CellTemplate () : DataTemplate
public function set CellTemplate (value : DataTemplate)
XAML Attribute Usage
<object CellTemplate="{ResourceExtension TemplateResourceKey}"/>

XAML Values

ResourceExtension

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

TemplateResourceKey

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

NoteNote:

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

Property Value

Type: System.Windows..::.DataTemplate
A DataTemplate that is used to format a column cell. The default is nullNothingnullptra null reference (Nothing in Visual Basic).
Dependency Property Information

Identifier field

CellTemplateProperty

Metadata properties set to true

None

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:

Examples

The following example shows how to specify a DataTemplate to use to display a GridViewColumn. For the complete sample, see ListView That Uses a GridView with Templates Sample.

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}"/>
Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5, 3.0
See Also

Reference

Change History

Date

History

Reason

July 2009

Changed second example to show referencing the DataTemplate in the first example.

Customer feedback.

Tags :


Page view tracker