# Customizing Groups Appearance

The `RadPropertyGrid` control in Progress® Telerik® UI for WPF supports a common style for all groups or a style selector for individual groups.

Both `GroupStyle` and `GroupStyleSelector` require `RenderMode` to be set to `Flat`. For more information about grouping, see [Grouping Support](https://www.telerik.com/products/wpf/documentation/controls/radpropertygrid/features/grouping).

## Set Up the PropertyGrid

The following examples use an `Employee` object as the `Item` of a grouped `RadPropertyGrid`.

Define the `Employee` class:

```C#
public class Employee
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string Title { get; set; }
    public string HomePhone { get; set; }
}
```

```VB.NET
	Public Class Employee
	    Public Property FirstName() As String
	    Public Property LastName() As String
	    Public Property Title() As String
	    Public Property HomePhone() As String
	End Class
```

Declare the `RadPropertyGrid` in XAML:

```XAML
<telerik:RadPropertyGrid x:Name="PropertyGrid" 
	                 RenderMode="Flat"   
	                 IsGrouped="True"
	                 AutoGeneratePropertyDefinitions="False">
    <telerik:RadPropertyGrid.PropertyDefinitions>
        <telerik:PropertyDefinition Binding="{Binding FirstName}" GroupName="Group Name" DisplayName="First Name" />
        <telerik:PropertyDefinition Binding="{Binding LastName}" GroupName="Group Name" DisplayName="Last Name"/>
        <telerik:PropertyDefinition Binding="{Binding Title}" GroupName="Group Title" DisplayName="Title"/>
        <telerik:PropertyDefinition Binding="{Binding HomePhone}" GroupName="Group Phone" DisplayName="HomePhone"/>
    </telerik:RadPropertyGrid.PropertyDefinitions>
</telerik:RadPropertyGrid>
```

Create the `Employee` object and assign it to the control:

```C#
Employee employee = new Employee()
{
    FirstName = "Nancy",
    LastName = "Porter",
    Title = "Sales Representative",
    HomePhone = "0088 888 3433"
};
PropertyGrid.Item = employee;
```

```VB.NET
	Dim employee As New Employee() With {
	    .FirstName = "Nancy",
	    .LastName = "Porter",
	    .Title = "Sales Representative",
	    .HomePhone = "0088 888 3433"
	}
	PropertyGrid.Item = employee
```

The following image shows the default group appearance:

![RadPropertyGrid with the default group appearance](https://www.telerik.com/products/wpf/documentation/assets/1557d2ac346c61f98f855ddedb49811f/radpropertygrid_groupstyle1.png)

## Apply a Common Group Style

To apply the same style to all groups, create a style resource:

```XAML
<Style x:Key="commonGroupStyle" TargetType="telerik:RadToggleButton">
    <Setter Property="Foreground" Value="Blue" />
    <Setter Property="HorizontalContentAlignment" Value="Center"/>
    <Setter Property="FontSize" Value="15"/>
    <Setter Property="Height"  Value="50" />
</Style>
```

Assign the resource to the `GroupStyle` property of the `RadPropertyGrid`:

```XAML
<telerik:RadPropertyGrid RenderMode="Flat"   
	                 IsGrouped="True"
	                 AutoGeneratePropertyDefinitions="False"
	                 GroupStyle="{StaticResource commonGroupStyle}" />
```

The following image shows the custom group style:

![RadPropertyGrid with a custom group style](https://www.telerik.com/products/wpf/documentation/assets/bd22d8d1bb978d55241d2d8d4cc926ce/radpropertygrid_groupstyle2.png)

## Select a Style for Each Group

Use `GroupStyleSelector` to choose a style based on the group. This example uses the `Employee` setup above and assigns different styles to the name, phone, and title groups.

Remove any local `GroupStyle` assignment before setting `GroupStyleSelector`. A locally set `GroupStyle`, including a local `null` value, takes precedence over the selector.

Create a class that inherits `StyleSelector` and overrides `SelectStyle`:

```C#
public class GroupStyleSelector : StyleSelector
{
    public override Style SelectStyle(object item, DependencyObject container)
    {
        GroupDefinition groupDef = item as GroupDefinition;
        if (groupDef.DisplayName == "Group Name")
        {
            return this.NameGroupStyle;
        }
        else if (groupDef.DisplayName == "Group Phone")
        {
            return this.PhoneGroupStyle;
        }
        else
        {
            return this.TitleGroupStyle;
        }
    }
    public Style NameGroupStyle { get; set; }
    public Style PhoneGroupStyle { get; set; }
    public Style TitleGroupStyle { get; set; }
}
```

```VB.NET
	Public Class GroupStyleSelector
	    Inherits StyleSelector
	    Public Overrides Function SelectStyle(ByVal item As Object, ByVal container As DependencyObject) As Style
	        Dim groupDef As GroupDefinition = TryCast(item, GroupDefinition)
	        If groupDef.DisplayName = "Group Name" Then
	            Return Me.NameGroupStyle
	        ElseIf groupDef.DisplayName = "Group Phone" Then
	            Return Me.PhoneGroupStyle
	        Else
	            Return Me.TitleGroupStyle
	        End If
	    End Function
	    Public Property NameGroupStyle() As Style
	    Public Property PhoneGroupStyle() As Style
	    Public Property TitleGroupStyle() As Style
	End Class
```

Define the selector as a XAML resource and set its `NameGroupStyle`, `PhoneGroupStyle`, and `TitleGroupStyle` properties:

```XAML
<my:GroupStyleSelector x:Key="groupStyleSelector">
    <my:GroupStyleSelector.NameGroupStyle>
        <Style TargetType="telerik:RadToggleButton">
            <Setter Property="Foreground" Value="Red"/>
        </Style>
    </my:GroupStyleSelector.NameGroupStyle>
    <my:GroupStyleSelector.PhoneGroupStyle>
        <Style TargetType="telerik:RadToggleButton">
            <Setter Property="Foreground" Value="Orange"/>
        </Style>
    </my:GroupStyleSelector.PhoneGroupStyle>
    <my:GroupStyleSelector.TitleGroupStyle>
        <Style TargetType="telerik:RadToggleButton">
            <Setter Property="Foreground" Value="Green"/>
        </Style>
    </my:GroupStyleSelector.TitleGroupStyle>
</my:GroupStyleSelector>
```

Map the `my` XAML prefix to the CLR namespace containing the selector class. When using implicit themes, base the styles on the default style for the corresponding theme:

```XAML
<Style TargetType="telerik:RadToggleButton" BasedOn="{StaticResource RadToggleButtonStyle}">
    <Setter Property="Foreground" Value="Green"/>
</Style>
```

Assign the selector resource to the `GroupStyleSelector` property of the `RadPropertyGrid`:

```XAML
<telerik:RadPropertyGrid x:Name="PropertyGrid" 
	                     RenderMode="Flat"   
	                     IsGrouped="True"
	                     GroupStyleSelector="{StaticResource groupStyleSelector}"
	                     AutoGeneratePropertyDefinitions="False">
    <telerik:RadPropertyGrid.PropertyDefinitions>
        <telerik:PropertyDefinition Binding="{Binding FirstName}" GroupName="Group Name" DisplayName="First Name" />
        <telerik:PropertyDefinition Binding="{Binding LastName}" GroupName="Group Name" DisplayName="Last Name"/>
        <telerik:PropertyDefinition Binding="{Binding Title}" GroupName="Group Title" DisplayName="Title"/>
        <telerik:PropertyDefinition Binding="{Binding HomePhone}" GroupName="Group Phone" DisplayName="HomePhone"/>
    </telerik:RadPropertyGrid.PropertyDefinitions>
</telerik:RadPropertyGrid>
```

The following image shows the styles selected for the groups:

![RadPropertyGrid with group-specific styles selected by a style selector](https://www.telerik.com/products/wpf/documentation/assets/c7be4eff7eacb34147a4fd9648beee60/radpropertygrid-group-style-selector.png)

## See Also

* [Grouping Support](https://www.telerik.com/products/wpf/documentation/controls/radpropertygrid/features/grouping)
* [Layout Rendering Modes](https://www.telerik.com/products/wpf/documentation/controls/radpropertygrid/features/layout-rendering-modes)
* [Setting a Theme Using Implicit Styles](https://www.telerik.com/products/wpf/documentation/styling-and-appearance/styling-apperance-setting-a-theme-overview)
* [Editing Control Templates](https://www.telerik.com/products/wpf/documentation/styling-and-appearance/styling-apperance-editing-control-templates)
