Back to Devexpress

ColumnBase.CellStyle Property

wpf-devexpress-dot-xpf-dot-grid-dot-columnbase-3f93871b.md

latest7.1 KB
Original Source

ColumnBase.CellStyle Property

Gets or sets the style of cells displayed within this column. This is a dependency property.

Namespace : DevExpress.Xpf.Grid

Assembly : DevExpress.Xpf.Grid.v25.2.Core.dll

NuGet Package : DevExpress.Wpf.Grid.Core

Declaration

csharp
public Style CellStyle { get; set; }
vb
Public Property CellStyle As Style

Property Value

TypeDescription
Style

The style of cells displayed within this column.

|

Remarks

Important

To format grid cells based on specific conditions, use Conditional Formatting to gain better performance. Refer to the following topic for more information - How to Conditionally Set Background and Foreground for Grid Rows and Cells.

The CellStyle property specifies a theme-independent style applied to cells within the current column. To specify a cell style for all columns, use the DataViewBase.CellStyle property. When both these properties are set, ColumnBase.CellStyle has higher priority.

To specify the styles applied to the column’s data cell displayed within the New Item Row and Automatic Filter Row, use the ColumnBase.NewItemRowCellStyle and ColumnBase.AutoFilterRowCellStyle properties.

TargetType

Optimized Mode

In optimized mode (the default setting), set TargetType to LightweightCellEditor.

xaml
<dxg:GridColumn>
    <dxg:GridColumn.CellStyle>
        <Style TargetType="dxg:LightweightCellEditor" />
    </dxg:GridColumn.CellStyle>
</dxg:GridColumn>
...
<dxg:TableView>
    <dxg:TableView.CellStyle>
        <Style TargetType="dxg:LightweightCellEditor" />
    </dxg:TableView.CellStyle>
</dxg:TableView>

Non-optimized Mode

If you disable the optimized mode, set TargetType to CellContentPresenter.

xaml
<dxg:GridColumn>
    <dxg:GridColumn.CellStyle>
        <Style TargetType="dxg:CellContentPresenter" />
    </dxg:GridColumn.CellStyle>
</dxg:GridColumn>
...
<dxg:TableView>
    <dxg:TableView.CellStyle>
        <Style TargetType="dxg:CellContentPresenter" />
    </dxg:TableView.CellStyle>
</dxg:TableView>

Data Binding

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

The following code snippets (auto-collected from DevExpress Examples) contain references to the CellStyle 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-synchronous-theme-preload-with-splashscreen/CS/ThemePreloadwithSplashscreen/ComplexWindow.xaml#L185

xml
<dxg:GridColumn FieldName="CreatedOn" FixedWidth="True">
    <dxg:GridColumn.CellStyle>
        <Style>

wpf-data-grid-define-cellstyle-and-celltemplate-in-code-behind/CS/fGrid11/MainWindow.xaml.cs#L27

csharp
style.Setters.Add(new Setter(LightweightCellEditor.BackgroundProperty, new SolidColorBrush(Colors.LightGreen)));
    gridControl1.Columns["LastName"].CellStyle = style;
}

wpf-data-grid-define-cellstyle-and-celltemplate-in-code-behind/VB/fGrid11/MainWindow.xaml.vb#L33

vb
_style.Setters.Add(New Setter(LightweightCellEditor.BackgroundProperty, New SolidColorBrush(Colors.LightGreen)))
    gridControl1.Columns("LastName").CellStyle = _style
End Sub

See Also

CellStyle

ActualCellStyle

NewItemRowCellStyle

AutoFilterRowCellStyle

How to avoid problems with the DXGrid virtualization mechanismKB article:

Appearance Customization

Print Data

ColumnBase Class

ColumnBase Members

DevExpress.Xpf.Grid Namespace