# Property Categories | WPF Controls | DevExpress Documentation

## Overview

The **PropertyGrid** control can divide the properties of the bound object into [categories](/WPF/116320/controls-and-libraries/property-grid/visual-elements/category). Properties from the same **category** are displayed within an expandable group. To specify a **category**, decorate a property of the bound object with the [Category attribute](https://learn.microsoft.com/dotnet/api/system.componentmodel.categoryattribute).  The **PropertyGrid** control automatically generates **category rows** based on the **category attribute** values.

The following example demonstrates how to decorate properties of the bound object with the **category attribute**.

- C#
- VB.NET

<section id="tabpanel_oigTGSN5VO_tabid-csharp" role="tabpanel" data-tab="tabid-csharp">
<pre><code class="lang-csharp">[Category(&quot;Contact&quot;)]
public string Email { get; set; }
[Category(&quot;Address&quot;)]
public string AddressLine1 { get; set; }
</code></pre></section>
<section id="tabpanel_oigTGSN5VO_tabid-vb" role="tabpanel" data-tab="tabid-vb" aria-hidden="true" hidden="hidden">
<pre><code class="lang-vb">&lt;Category(&quot;Contact&quot;)&gt;
Public Property Email As String
&lt;Category(&quot;Address&quot;)&gt;
Public Property AddressLine1 As String
</code></pre></section>

Users can switch between **categorized** and **flat** display modes at runtime using the [tool panel](/WPF/15624/controls-and-libraries/property-grid/visual-elements/tool-panel). To specify the default **category display mode**, use the [PropertyGridControl.ShowCategories](/WPF/DevExpress.Xpf.PropertyGrid.PropertyGridControl.ShowCategories) property. The image below demonstrates both display modes.

![PG_flat_categorized](/WPF/images/pg_flat_categorized124854.png)

Set the [ExpandCategoriesWhenSelectedObjectChanged](/WPF/DevExpress.Xpf.PropertyGrid.PropertyGridControl.ExpandCategoriesWhenSelectedObjectChanged) property to **true** to automatically expand all categories when the user selects another object.

## Using Category Definitions

**Category definitions** represent the [category rows](/WPF/116320/controls-and-libraries/property-grid/visual-elements/category) and specify their appearance within the property grid. **Category definitions** are represented by the[CategoryDefinition](/WPF/DevExpress.Xpf.PropertyGrid.CategoryDefinition) objects that are stored within the [PropertyGridControl.PropertyDefinitions](/WPF/DevExpress.Xpf.PropertyGrid.PropertyGridControl.PropertyDefinitions) collection.

The following example demonstrates the [CategoryDefinition](/WPF/DevExpress.Xpf.PropertyGrid.CategoryDefinition) objects that specify the custom category headers.

- C#
- VB.NET

<section id="tabpanel_oigTGSN5VO-1_tabid-csharp" role="tabpanel" data-tab="tabid-csharp">
<pre><code data-code-links="{&quot;/ (System.ComponentModel)(?:;|$)/&quot;:&quot;https://learn.microsoft.com/dotnet/api/system.componentmodel&quot;}" class="lang-csharp">using System.ComponentModel;
...
public class Supplier {
    [Category(&quot;Info&quot;)]
    public int ID { get; set; }
    [Category(&quot;Info&quot;)]
    public string Name { get; set; }
    [Category(&quot;Contact&quot;)]
    public string Email { get; set; }
    [Category(&quot;Contact&quot;)]
    public string Phone { get; set; }
}

public class ViewModel {
    public Supplier DemoSupplier { get; set; }
    public ViewModel() {
        DemoSupplier = new Supplier()
        {
            ID = 0,
            Name = &quot;Anita Benson&quot;,
            Email = &quot;Anita_Benson@example.com&quot;,
            Phone = &quot;7138638137&quot;
        };
    }
}
</code></pre></section>
<section id="tabpanel_oigTGSN5VO-1_tabid-vb" role="tabpanel" data-tab="tabid-vb" aria-hidden="true" hidden="hidden">
<pre><code data-code-links="{&quot;/ (System.ComponentModel)(?:;|$)/&quot;:&quot;https://learn.microsoft.com/dotnet/api/system.componentmodel&quot;}" class="lang-vb">Imports System.ComponentModel

Public Class Supplier
    &lt;Category(&quot;Info&quot;)&gt;
    Public Property ID As Integer
    &lt;Category(&quot;Info&quot;)&gt;
    Public Property Name As String
    &lt;Category(&quot;Contact&quot;)&gt;
    Public Property Email As String
    &lt;Category(&quot;Contact&quot;)&gt;
    Public Property Phone As String
End Class

Public Class ViewModel
    Public Property DemoSupplier As Supplier

    Public Sub New()
        DemoSupplier = New Supplier() With {
            .ID = 0,
            .Name = &quot;Anita Benson&quot;,
            .Email = &quot;Anita_Benson@example.com&quot;,
            .Phone = &quot;7138638137&quot;
        }
    End Sub
End Class
</code></pre></section>

- XAML

<section id="tabpanel_oigTGSN5VO-2_tabid-xaml" role="tabpanel" data-tab="tabid-xaml">
<pre><code class="lang-xaml">&lt;Window.DataContext&gt;
    &lt;local:ViewModel/&gt;
&lt;/Window.DataContext&gt;
...
&lt;dxprg:PropertyGridControl SelectedObject=&quot;{Binding DemoSupplier}&quot;
                           ShowProperties=&quot;All&quot; ShowCategories=&quot;Visible&quot;&gt;
    &lt;dxprg:CategoryDefinition Path=&quot;Info&quot; Header=&quot;Personal Information&quot;/&gt;
    &lt;dxprg:CategoryDefinition Path=&quot;Contact&quot; Header=&quot;Contact Information&quot;/&gt;
&lt;/dxprg:PropertyGridControl&gt;
</code></pre></section>

The image below demonstrates the result.

![PG_Category_Visible](/WPF/images/pg_category_visible124825.png)

## Tabbed View

To display each **category** in a separate tab, set the [PropertyGridControl.ShowCategories](/WPF/DevExpress.Xpf.PropertyGrid.PropertyGridControl.ShowCategories) property to **Tabbed**.  

![PG_Category_Tabbed](/WPF/images/pg_category_tabbed124826.png)

The following example demonstrates how to use the [CategoryDefinition](/WPF/DevExpress.Xpf.PropertyGrid.CategoryDefinition) objects to specify a glyph for each tab header.

- C#
- VB.NET

<section id="tabpanel_oigTGSN5VO-3_tabid-csharp" role="tabpanel" data-tab="tabid-csharp">
<pre><code data-code-links="{&quot;/ (System.ComponentModel)(?:;|$)/&quot;:&quot;https://learn.microsoft.com/dotnet/api/system.componentmodel&quot;}" class="lang-csharp">using System.ComponentModel;

public class Supplier {
    [Category(&quot;Info&quot;)]
    public int ID { get; set; }
    [Category(&quot;Info&quot;)]
    public string Name { get; set; }
    [Category(&quot;Contact&quot;)]
    public string Email { get; set; }
    [Category(&quot;Contact&quot;)]
    public string Phone { get; set; }
}

public class ViewModel {
    public Supplier DemoSupplier { get; set; }
    public ViewModel() {
        DemoSupplier = new Supplier()
        {
            ID = 0,
            Name = &quot;Anita Benson&quot;,
            Email = &quot;Anita_Benson@example.com&quot;,
            Phone = &quot;7138638137&quot;
        };
    }
}
</code></pre></section>
<section id="tabpanel_oigTGSN5VO-3_tabid-vb" role="tabpanel" data-tab="tabid-vb" aria-hidden="true" hidden="hidden">
<pre><code data-code-links="{&quot;/ (System.ComponentModel)(?:;|$)/&quot;:&quot;https://learn.microsoft.com/dotnet/api/system.componentmodel&quot;}" class="lang-vb">Imports System.ComponentModel

Public Class Supplier
    &lt;Category(&quot;Info&quot;)&gt;
    Public Property ID As Integer
    &lt;Category(&quot;Info&quot;)&gt;
    Public Property Name As String
    &lt;Category(&quot;Contact&quot;)&gt;
    Public Property Email As String
    &lt;Category(&quot;Contact&quot;)&gt;
    Public Property Phone As String
End Class

Public Class ViewModel
    Public Property DemoSupplier As Supplier

    Public Sub New()
        DemoSupplier = New Supplier() With {
            .ID = 0,
            .Name = &quot;Anita Benson&quot;,
            .Email = &quot;Anita_Benson@example.com&quot;,
            .Phone = &quot;7138638137&quot;
        }
    End Sub
End Class
</code></pre></section>

- XAML

<section id="tabpanel_oigTGSN5VO-4_tabid-xaml" role="tabpanel" data-tab="tabid-xaml">
<pre><code class="lang-xaml">&lt;Window 
        ...
        xmlns:dx=&quot;http://schemas.devexpress.com/winfx/2008/xaml/core&quot;&gt;
&lt;Window.DataContext&gt;
    &lt;local:ViewModel/&gt;
&lt;/Window.DataContext&gt;
...
&lt;dxprg:PropertyGridControl SelectedObject=&quot;{Binding DemoSupplier}&quot; ShowProperties=&quot;All&quot; ShowCategories=&quot;Tabbed&quot;&gt;
    &lt;dxprg:CategoryDefinition Path=&quot;Info&quot; Glyph=&quot;{dx:DXImage Image=Female_32x32.png}&quot;/&gt;
    &lt;dxprg:CategoryDefinition Path=&quot;Contact&quot; Glyph=&quot;{dx:DXImage Image=Contact_32x32.png}&quot;/&gt;
&lt;/dxprg:PropertyGridControl&gt;
</code></pre></section>

## Applying Mode

You can create different property definitions for each of the display modes. The [PropertyDefinitionBase.ApplyingMode](/WPF/DevExpress.Xpf.PropertyGrid.PropertyDefinitionBase.ApplyingMode) property specifies whether a property definition should be applied in the categorized or flat mode.

The example below demonstrates a property grid that is configured in the following way.

- The **ID** property is visible in both the **flat** and **categorized** display modes.
- The **Email** property is visible in the **categorized** mode only.
- The **Name** property has different descriptions in each of the display modes.

- XAML

<section id="tabpanel_oigTGSN5VO-5_tabid-xaml1" role="tabpanel" data-tab="tabid-xaml1">
<pre><code class="lang-xaml">&lt;dxprg:PropertyGridControl SelectedObject=&quot;{Binding DemoSupplier}&quot; ShowProperties=&quot;WithPropertyDefinitions&quot;&gt;
    &lt;dxprg:CategoryDefinition Path=&quot;Info&quot; Header=&quot;Personal Information&quot;/&gt;
    &lt;dxprg:CategoryDefinition Path=&quot;Contact&quot; Header=&quot;Contact Information&quot;/&gt;

    &lt;dxprg:PropertyDefinition Path=&quot;ID&quot; Description=&quot;Customer&#39;s ID&quot; ApplyingMode=&quot;Always&quot;/&gt;
    &lt;dxprg:PropertyDefinition Path=&quot;Email&quot; Description=&quot;Email&quot; ApplyingMode=&quot;WhenGrouping&quot;/&gt;
    &lt;dxprg:PropertyDefinition Path=&quot;Name&quot; Description=&quot;Name Catagorized&quot; ApplyingMode=&quot;WhenGrouping&quot;/&gt;
    &lt;dxprg:PropertyDefinition Path=&quot;Name&quot; Description=&quot;Name Flat&quot; ApplyingMode=&quot;WhenNoGrouping&quot;/&gt;
&lt;/dxprg:PropertyGridControl&gt;
</code></pre></section>

![PG_ApplyingMode](/WPF/images/pg_applyingmode124973.png)

### Limitation

If you have two definitions with equal Path property values and different [PropertyDefinitionBase.ApplyingModes](/WPF/DevExpress.Xpf.PropertyGrid.PropertyDefinitionBase.ApplyingMode), the [PropertyGridControl](/WPF/DevExpress.Xpf.PropertyGrid.PropertyGridControl) does not update its property definitions when you switch the [PropertyGridControl.ShowCategories](/WPF/DevExpress.Xpf.PropertyGrid.PropertyGridControl.ShowCategories) property’s value at runtime.

- XAML

<section id="tabpanel_oigTGSN5VO-6_tabid-xaml1" role="tabpanel" data-tab="tabid-xaml1">
<pre><code data-highlight-lines="[[2],[3]]" class="lang-xaml">&lt;dxprg:PropertyGridControl SelectedObject=&quot;{Binding DemoSupplier}&quot; ShowProperties=&quot;WithPropertyDefinitions&quot;&gt;
    &lt;dxprg:PropertyDefinition Path=&quot;Name&quot; Description=&quot;Name Catagorized&quot; ApplyingMode=&quot;WhenGrouping&quot;/&gt;
    &lt;dxprg:PropertyDefinition Path=&quot;Name&quot; Description=&quot;Name Flat&quot; ApplyingMode=&quot;WhenNoGrouping&quot;/&gt;
&lt;/dxprg:PropertyGridControl&gt;
</code></pre></section>

You can declare a custom [PropertyGridControl](/WPF/DevExpress.Xpf.PropertyGrid.PropertyGridControl) descendant and override its `OnShowCategoriesChanged` method to force the [PropertyGridControl](/WPF/DevExpress.Xpf.PropertyGrid.PropertyGridControl) to regenerate its definitions when you change [ShowCategories](/WPF/DevExpress.Xpf.PropertyGrid.PropertyGridControl.ShowCategories) mode:

- C#
- VB.NET

<section id="tabpanel_oigTGSN5VO-7_tabid-csharp" role="tabpanel" data-tab="tabid-csharp">
<pre><code class="lang-csharp">public class MyPropertyGridControl : PropertyGridControl {
    protected override void OnShowCategoriesChanged(CategoriesShowMode oldValue) {
        base.OnShowCategoriesChanged(oldValue);
        this.DataController.ResetCache();
    }
} 
</code></pre></section>
<section id="tabpanel_oigTGSN5VO-7_tabid-vb" role="tabpanel" data-tab="tabid-vb" aria-hidden="true" hidden="hidden">
<pre><code class="lang-vb">Public Class MyPropertyGridControl
    Inherits PropertyGridControl

    Protected Overrides Sub OnShowCategoriesChanged(ByVal oldValue As CategoriesShowMode)
        MyBase.OnShowCategoriesChanged(oldValue)
        Me.DataController.ResetCache()
    End Sub
End Class
</code></pre></section>

See Also

[Property Definitions](/WPF/15521/controls-and-libraries/property-grid/property-definitions)