Xceed DataGrid for WPF v7.2 Documentation
CellContentTemplate Property
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
'Declaration
 
Public Property CellContentTemplate As DataTemplate
'Usage
 
Dim instance As ColumnBase
Dim value As DataTemplate
 
instance.CellContentTemplate = value
 
value = instance.CellContentTemplate
public DataTemplate CellContentTemplate {get; set;}

Property 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.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.
<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>
<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

Target Platforms: Windows 11, Windows, 10, 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

See Also

Reference

ColumnBase Class
ColumnBase Members