This documentation is archived and is not being maintained.
DataGridTemplateColumn::CellTemplate Property
Visual Studio 2010
Gets or sets the template to use to display the contents of a cell that is not in editing mode.
Assembly: PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
public: property DataTemplate^ CellTemplate { DataTemplate^ get (); void set (DataTemplate^ value); }
<object> <object.CellTemplate> <DataTemplate .../> </object.CellTemplate> </object>
Property Value
Type: System.Windows::DataTemplateThe template to use to display the contents of a cell that is not in editing mode. The registered default is nullptr. For information about what can influence the value, see DependencyProperty.
The cell template defines how the content is displayed in the column cells. For more information about data templates, see Data Templating Overview and Styling and Templating.
To define the template for a cell that is in editing mode, use the CellEditingTemplate.
The following example shows how to create the CellTemplate for displaying a column of dates.
<Grid> <Grid.Resources> <!--DataTemplate for Published Date column defined in Grid.Resources. PublishDate is a property on the ItemsSource of type DateTime --> <DataTemplate x:Key="DateTemplate" > <StackPanel Width="20" Height="30"> <Border Background="LightBlue" BorderBrush="Black" BorderThickness="1"> <TextBlock Text="{Binding PublishDate, StringFormat={}{0:MMM}}" FontSize="8" HorizontalAlignment="Center" /> </Border> <Border Background="White" BorderBrush="Black" BorderThickness="1"> <TextBlock Text="{Binding PublishDate, StringFormat={}{0:yyyy}}" FontSize="8" FontWeight="Bold" HorizontalAlignment="Center" /> </Border> </StackPanel> </DataTemplate> <!--DataTemplate for the Published Date column when in edit mode. --> <DataTemplate x:Key="EditingDateTemplate"> <DatePicker SelectedDate="{Binding PublishDate}" /> </DataTemplate> </Grid.Resources> <DataGrid Name="DG1" ItemsSource="{Binding}" AutoGenerateColumns="False" > <DataGrid.Columns> <!--Custom column that shows the published date--> <DataGridTemplateColumn Header="Publish Date" CellTemplate="{StaticResource DateTemplate}" CellEditingTemplate="{StaticResource EditingDateTemplate}" /> </DataGrid.Columns> </DataGrid> </Grid>
The following illustration shows the output from the previous XAML.

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Show: