wpf-devexpress-dot-xpf-dot-grid-dot-columnbase-668fba76.md
Gets or sets a template that displays column values. This is a dependency property.
Namespace : DevExpress.Xpf.Grid
Assembly : DevExpress.Xpf.Grid.v25.2.Core.dll
NuGet Package : DevExpress.Wpf.Grid.Core
public DataTemplate CellDisplayTemplate { get; set; }
Public Property CellDisplayTemplate As DataTemplate
| Type | Description |
|---|---|
| DataTemplate |
A template that displays column values.
|
The binding source for the CellDisplayTemplate is EditGridCellData. Refer to the Data Binding section.
To apply different cell templates based on certain conditions, use a custom CellDisplayTemplateSelector. If both the CellDisplayTemplate and CellDisplayTemplateSelector are specified, the template returned by the template selector has a higher priority. If the template selector returns null , the template specified by the CellDisplayTemplate property is used.
Each column has the following templates that define editors for display and edit modes:
| Template | Description |
|---|---|
| ColumnBase.CellDisplayTemplate / DataViewBase.CellDisplayTemplate | Defines a template that displays column values. |
| ColumnBase.CellEditTemplate / DataViewBase.CellEditTemplate | Defines a template that represents an editor used to edit cell values. |
We recommend that you use a custom editor in the cell template as follows:
This technique has the following advantages:
View Example: How to Use Custom Editors to Edit Cell Values
You can use non-BaseEdit cell editors in the CellDisplayTemplate to display and edit data. This method has the following limitations:
In the following code sample, a numeric column uses the ProgressBarEdit editors to display data. When users focus cells, the TrackBarEdit editors replace progress bars:
<dxg:GridControl>
<!-- ... -->
<dxg:GridColumn FieldName="UnitsOnOrder">
<dxg:GridColumn.CellDisplayTemplate>
<DataTemplate>
<dxe:ProgressBarEdit Name="PART_Editor" Minimum="0" Maximum="50" />
</DataTemplate>
</dxg:GridColumn.CellDisplayTemplate>
<dxg:GridColumn.CellEditTemplate>
<DataTemplate>
<dxe:TrackBarEdit Name="PART_Editor" Minimum="0" Maximum="50" />
</DataTemplate>
</dxg:GridColumn.CellEditTemplate>
</dxg:GridColumn>
<!-- ... -->
</dxg:GridControl>
Cell elements contain EditGridCellData objects in their DataContext.
Use the following binding paths to access cell values, columns, and ViewModel properties:
Value - access the current cell value;Column - access the current column;RowData.Row.[YourPropertyName] - access a property of an object from the ItemsSource collection;Data.[FieldName] - access column values in Server Mode or if you use the RealTimeSource, access unbound column values;View.DataContext.[YourPropertyName] - access a property in a grid’s ViewModel.View Example: Build Binding Paths in WPF Data Grid Cells
When you use the CellDisplayTemplate, the editor specified in the EditSettings property is ignored. However, the EditSettings value affects the formatting settings, data processing (sorting, grouping, filtering, summary calculation), and export.
The following code snippets (auto-collected from DevExpress Examples) contain references to the CellDisplayTemplate property.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.
wpf-data-grid-embed-a-richtextbox-into-grid-cells/CS/Window1.xaml#L37
<dxg:GridColumn Header="Description" FieldName="RtfContent" AllowGrouping="False" Width="400">
<dxg:GridColumn.CellDisplayTemplate>
<DataTemplate>
wpf-grid-read-only-and-enabled-binding/CS/MainWindow.xaml#L30
<dxg:TreeListColumn FieldName="Status" Header="Progress" FixedWidth="True" Width="100" IsReadOnlyBinding="{Binding HasSubtasks}">
<dxg:TreeListColumn.CellDisplayTemplate>
<DataTemplate>
See Also
Choosing Templates Based on Custom Logic
How to avoid problems with the DXGrid virtualization mechanism: