CellContentTemplate Property
See Also  Example
Xceed.Wpf.DataGrid Assembly > Xceed.Wpf.DataGrid Namespace > ColumnBase Class : CellContentTemplate Property

Gets or sets the DataTemplate used to display the cells' content.

Syntax

Visual Basic (Declaration) 
Public Property CellContentTemplate As DataTemplate
C# 
public DataTemplate CellContentTemplate {get; set;}

Return Value

A reference to the DataTemplate used to display the cells' content. By default, a null reference (Nothing in Visual Basic).

Example

All examples in this topic assume that the grid is bound to the Products table of the Northwind database, unless stated otherwise
The following example demonstrates how to provide a new CellContentTemplate, using property element syntax, for a boolean column that displays a check mark when the cell's value is true, and an x when it is false.
XAMLCopy Code
<Grid xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid">  
  <Grid.Resources>  
    <xcdg:DataGridCollectionViewSource x:Key="cvs_products"  
                                    Source="{Binding Source={x:Static Application.Current},  
                                                      Path=Products}"/>  
  </Grid.Resources>  
   <xcdg:DataGridControl x:Name="ProductsGrid"  
                         ItemsSource="{Binding Source={StaticResource cvs_products}}">  
      <xcdg:DataGridControl.Columns>  
  
        <xcdg:Column FieldName="Discontinued">  
           <xcdg:Column.CellContentTemplate>  
              <DataTemplate>  
                 <Image x:Name="img" Source="D:\true.png" Stretch="None" />  
                    <DataTemplate.Triggers>  
                       <DataTrigger Binding="{Binding}" Value="False">  
                         <Setter TargetName="img" Property="Source" Value="D:\false.png" />  
                       </DataTrigger>  
                    </DataTemplate.Triggers>  
              </DataTemplate>  
           </xcdg:Column.CellContentTemplate>  
        </xcdg:Column>  
      </xcdg:DataGridControl.Columns>  
   </xcdg:DataGridControl>  
</Grid>
The following example demonstrates how to format a cell's content to display a numeric value as a currency value. Although it might be tempting to apply the converter to a column's DisplayMemberBinding, this is not the recommended location as not only will the cells' content be formatted but the data type of the cells' content will be changed to the converter's.
XAMLCopy Code
<Grid xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid"  
      xmlns:local="clr-namespace:Xceed.Wpf.Documentation">  
  <Grid.Resources>  
    <xcdg:DataGridCollectionViewSource x:Key="cvs_orderdetails"  
                                    Source="{Binding Source={x:Static Application.Current},   
                                                      Path=OrderDetails}"/>             
             
  
    <xcdg:CurrencyConverter x:Key="currencyConverter"/>  
  
    <DataTemplate x:Key="currency_celltemplate">  
      <TextBlock Text="{Binding Converter={StaticResource currencyConverter}}"/>  
    </DataTemplate>  
  </Grid.Resources>  
  
  <xcdg:DataGridControl x:Name="OrderDetailGrid"  
                        ItemsSource="{Binding Source={StaticResource cvs_orderdetails}}">  
    <xcdg:DataGridControl.Columns>  
  
      <xcdg:Column FieldName="UnitPrice"  
                   CellContentTemplate="{StaticResource currency_celltemplate}"/>  
    </xcdg:DataGridControl.Columns>  
  </xcdg:DataGridControl>  
</Grid>

Requirements

Supported Frameworks: Microsoft .NET Framework version 3.5

See Also