New to Telerik UI for WPFStart a free 30-day trial

MergedCellsStyleSelector

Updated on Jul 17, 2026

RadGridView's MergedCellsStyleSelector can be used to style merged cells differently based on a specific condition.

Bear in mind that the MergedCellsStyle takes precedence over the MergedCellsStyleSelector and will overwrite it if both are defined simultaneously.

To do so, first create a new class that inherits the StyleSelector class and override its SelectStyle method:

Example 1: The StadiumCapacityStyleSelector class

C#
	public class StadiumCapacityStyleSelector : StyleSelector
    {
        public override Style SelectStyle(object item, DependencyObject container)
        {
            var cell = item as MergedCellInfo;

            if (cell != null)
            {
                if (int.Parse(cell.Value.ToString()) > 50000)
                {
                    return BigStadiumStyle;
                }
                else
                {
                    return SmallStadiumStyle;
                }
            }

            return null; 
        }
        public Style BigStadiumStyle { get; set; }
        public Style SmallStadiumStyle { get; set; }
    }

In the XAML file, define the style selector as a resource and set the properties of the BigStadiumStyle and SmallStadiumStyle:

Example 2: Setting the BigStadiumStyle and SmallStadiumStyle

XAML
	<Grid.Resources>
        <my:StadiumCapacityStyleSelector x:Key="StadiumCapacityStyleSelector">
            <my:StadiumCapacityStyleSelector.BigStadiumStyle>
                <Style TargetType="telerik:GridViewMergedCell">
                    <Setter Property="Background" Value="Red"/>
                </Style>
            </my:StadiumCapacityStyleSelector.BigStadiumStyle>
            <my:StadiumCapacityStyleSelector.SmallStadiumStyle>
                <Style TargetType="telerik:GridViewMergedCell">
                    <Setter Property="Background" Value="Yellow" />
                </Style>
            </my:StadiumCapacityStyleSelector.SmallStadiumStyle>
        </my:StadiumCapacityStyleSelector>
	</Grid.Resources>

The "my:" prefix before StadiumCapacityStyleSelector specifies the mapping for the namespace of the project: xmlns:my="..."

Finally, set the MergedCellsStyleSelector property:

Example 3: Setting the MergedCellsStyleSelector property

XAML
	<telerik:RadGridView MergedCellsDirection="Vertical" MergedCellsStyleSelector="{StaticResource StadiumCapacityStyleSelector}" />

And here is the final result:

Figure 1: The merged cells styled using the MergedCellsStyleSelector property

Telerik UI for WPF RadGridView with MergedCellsStyleSelector applying different styles to vertically merged cells

See Also

In this article
See Also
Not finding the help you need?
Contact Support