New to Telerik UI for WPF? Download free 30-day trial

Styling Cells

In this article, we discuss various approaches to style the RadGridView cells:

To get the most of this article, make sure you are already familiar with the Template Structure of the GridViewCell.

Figure 1: GridViewCell template structure

Telerik WPF DataGrid Cell Template

Styling all RadGridView Cells

The examples from this article assume that the RadGridView is set up as demonstrated in its Getting Started article.

To style all RadGridView cells of an application, create a style that targets 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.

Example 1: Styling all cells of an application

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

If you're using Implicit Styles, base your style on the GridViewCellStyle that is defined for the corresponding theme.

Figure 2: RadGridView with styled cells in the Office2016 theme

Telerik WPF DataGrid-Cell-Styled

Setting a Column's CellStyle

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

Example 2: Setting a column's CellStyle

<Grid> 
    <Grid.Resources> 
        <Style x:Key="GridViewCellStyle" TargetType="telerik:GridViewCell"> 
            <Setter Property="VerticalContentAlignment" Value="Top"/> 
            <Setter Property="HorizontalContentAlignment" Value="Center"/> 
            <Setter Property="Background" Value="#ffcc00"/> 
        </Style> 
    </Grid.Resources> 
 
    <telerik:RadGridView ItemsSource="{Binding Clubs}" 
                         AutoGenerateColumns="False" 
                         GroupRenderMode="Flat"> 
        <telerik:RadGridView.Columns> 
            <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}" 
                Header="Name" 
                CellStyle="{StaticResource GridViewCellStyle}" /> 
        </telerik:RadGridView.Columns> 
    </telerik:RadGridView> 
</Grid> 

Setting a Column's CellStyleSelector

You could also use a column's CellStyleSelector property to style cells differently based on a specific condition. For more details about this approach, see the CellStyleSelector article.

Setting the SelectedBackground of the Cell

As of RadGridView R3 2018, you can set the Background of the selected cell by setting the SelectedBackground property of the GridViewCell.

Example 3: Setting the SelectedBackground of the GridViewCell

<Application.Resources> 
    <ResourceDictionary> 
        <Style TargetType="telerik:GridViewCell"> 
            <Setter Property="SelectedBackground" Value="Bisque" /> 
        </Style> 
    </ResourceDictionary> 
</Application.Resources> 

Figure 3: Result from Example 3 in the Office2016 theme

Telerik WPF DataGrid-selected-background-cell

Setting the BorderBrush of the CurrentCell

As of RadGridView R3 2018, you can set the BorderBrush of the current cell, by setting the CurrentBorderBrush property of the GridViewCell.

Example 4 demonstrates how to set the BorderBrush of the current cell to transparent. You can compare Figure 3 and Figure 4 to notice that the border of the current cell is not visible.

Example 4: Setting the CurrentBorderBrush of the GridViewCell

<Application.Resources> 
    <ResourceDictionary> 
        <Style TargetType="telerik:GridViewCell"> 
            <Setter Property="CurrentBorderBrush" Value="Transparent" /> 
        </Style> 
    </ResourceDictionary> 
</Application.Resources> 

Figure 4: Result from Example 4 in the Office2016 theme

Telerik WPF DataGrid-currentborderbrush

After you have set the CurrentBorderBrush to Transparent, if you start navigating through the cells with the keyboard, you will be able to see the FocusVisual border. If you want to hide it as well, you can set the FocusVisualStyle of the GridViewCell to null through a style similar to Example 4.

Setting the MouseOverBackground of the Cell

As of RadGridView R1 2019 SP1, you can change the MouseOver Background of the cells through the MouseOverBackground property of the GridViewCell. This is demonstrated in Example 5.

Example 5: Setting the MouseOverBackground of the GridViewCell

<Application.Resources> 
    <ResourceDictionary> 
        <Style TargetType="telerik:GridViewCell" > 
            <Setter Property="MouseOverBackground" Value="Pink" /> 
        </Style> 
    </ResourceDictionary> 
</Application.Resources> 

Figure 5: Result from Example 5 in the Office2016 theme

RadGridView with MouseOverBackground for the cells

In order for the MouseOverBackground of the cell to take effect, set the SelectionUnit of RadGridView to Mixed or Cell.

See Also

In this article
Not finding the help you need? Improve this article