Edit this page

Styling Cells

Before reading this topic, you might find it useful to get familiar with the Template Structure of the GridViewCell.

In this article we will discuss the following topics:

Figure 1: GridViewCell template structure

GridViewCell template structure

Targeting the GridViewCell Element

In order to style all RadGridView cells of an application, you should create an appropriate style targeting the GridViewCell element.

You have two options:

  • To create an empty style and set it up on your own.

  • To copy the default style of the control and modify it.

To learn how to modify the default GridViewCell style, please refer to the Modifying Default Styles article.

[XAML] Example 1: Styling all cells of an application

<Style TargetType="telerik:GridViewCell">
    <Setter Property="VerticalContentAlignment" Value="Top"/>
    <Setter Property="HorizontalContentAlignment" Value="Center"/>
    <Setter Property="Background" Value="#ffcc00"/>
</Style>

If you're using Implicit Styles, you should base your style on the GridViewCellStyle.

Figure 2: RadGridView with styled cells

RadGridView with styled cells

Setting a Column's CellStyle

RadGridView Cells can also be styled by creating an appropriate Style for the GridViewCell element and setting it as the CellStyle property of the respective GridView Column.

[XAML] Example 2: Setting a column's CellStyle

<telerik:GridViewDataColumn DataMemberBinding="{Binding Name}"
                Header="Name"
                CellStyle="{StaticResource GridViewCellStyle}" />

Setting a Column's CellStyleSelector

You could also use a column's CellStyleSelector property to style cells differently based on a specific condition. More details about how this can be achieved can be found in the CellStyleSelector article.

See Also