CellContentTemplate Property
'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).
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>
.NET: net5.0, net5.0-windows, net6.0, net6.0-macos, net6.0-windows, net7.0, net7.0-macos, net7.0-windows, net8.0, net8.0-browser, net8.0-macos, net8.0-windows, net9.0, net9.0-browser, net9.0-macos, net9.0-windows, net10.0, net10.0-browser, net10.0-macos, net10.0-windows.
.NET Framework: net40, net403, net45, net451, net452, net46, net461, net462, net463, net47, net471, net472, net48, net481.