All docs
V20.1
20.1
19.2
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.

Customize Properties

  • 6 minutes to read

This topic shows how to customize cell editors, headers, and description in the Property Grid.

Cell Editors

The PropertyGridControl creates cell editors based on property types.

public class Item {
    public DateTime BirthDate { get; set; }
}

Use the following properties to display another content in property grid cells or additionally configure cell editors.

Member

Task

EditSettings

CellTemplate

Assign and configure a cell editor

ContentTemplate

Display a different property value

Display multiple property values in a single row

EditSettings

These approaches are compatible with all BaseEditSettings class descendants.

Approach 1: Set the EditSettings property

Create a property definition and set the EditSettings property for it.

xmlns:sys="clr-namespace:System;assembly=mscorlib"

<dxprg:PropertyDefinition Type="sys:DateTime">
    <dxprg:PropertyDefinition.EditSettings>
        <dxe:DateEditSettings DisplayFormat="MMM-dd-yyyy" />
    </dxprg:PropertyDefinition.EditSettings>
</dxprg:PropertyDefinition>

Approach 2: Use attributes or the DevExpress Fluent API

Create a template with a BaseEditSettings class descendant and use DevExpress.Mvvm.DataAnnotations.DefaultEditorAttribute, DevExpress.Mvvm.DataAnnotations.PropertyGridEditorAttribute, or the DevExpress Fluent API to specify this template key.

static MainWindow() {
    MetadataLocator.Default = MetadataLocator.Create().AddMetadata<ItemMetadata>();
}
public class Item {
    public DateTime Date { get; set; }
}
public class ItemMetadata : IMetadataProvider<Item> {
    public void BuildMetadata(MetadataBuilder<Item> builder) {
        builder.Property(x => x.Date).PropertyGridEditor("DateEditor");
    }
}
<Window.Resources>
    <DataTemplate x:Key="DateEditor">
        <dxe:DateEditSettings Mask="dd-MM-yyyy" MaskUseAsDisplayFormat="True" />
    </DataTemplate>
</Window.Resources>

CellTemplate

The table below shows the key differences between the EditSettings and CellTemplate properties.

EditSettings

CellTemplate

Performance

Normal

Lower

Display custom editors

no

yes

Editor settings

Editors in all properties associated with the current property definition have similar settings

Editors may have different settings, for example, depending on the current property value

Priority

Standard

Higher

To gain the best user experience, use a DevExpress editor and set the editor's Name to 'PART_Editor'. For example:

<DataTemplate>
    <dxe:DateEdit Name="PART_Editor" DisplayFormatString="MMM-dd-yyyy" />
</DataTemplate>

Approach 1: Set the CellTemplate property

Create a property definition and set the CellTemplate property for it.

xmlns:sys="clr-namespace:System;assembly=mscorlib"

<dxprg:PropertyDefinition Type="sys:DateTime">
    <dxprg:PropertyDefinition.CellTemplate>
        <DataTemplate>
            <dxe:DateEdit Name="PART_Editor" DisplayFormatString="MMM-dd-yyyy" />
        </DataTemplate>
    </dxprg:PropertyDefinition.CellTemplate>
</dxprg:PropertyDefinition>

Approach 2: Use attributes or the DevExpress Fluent API

Create a template with a DevExpress editor whose name is set to PART_Editor and use DevExpress.Mvvm.DataAnnotations.DefaultEditorAttribute, DevExpress.Mvvm.DataAnnotations.PropertyGridEditorAttribute, or the DevExpress Fluent API to specify this template key.

static MainWindow() {
    MetadataLocator.Default = MetadataLocator.Create().AddMetadata<ItemMetadata>();
}
public class Item {
    public DateTime Date { get; set; }
}
public class ItemMetadata : IMetadataProvider<Item> {
    public void BuildMetadata(MetadataBuilder<Item> builder) {
        builder.Property(x => x.Date).PropertyGridEditor("DateEditor");
    }
}
<Window.Resources>
    <DataTemplate x:Key="DateEditor">
        <dxe:DateEdit Mask="dd-MM-yyyy" MaskUseAsDisplayFormat="True" />
    </DataTemplate>
</Window.Resources>

ContentTemplate

PropertyDefinitionBase.ContentTemplate should contain CellEditorPresenter controls with the Path property set. Set PathMode to manage where CellEditorPresenter should look for a property specified in Path. The table below describes the available options.

Value

Description

Relative (default)

The CellEditorPresenter.Path points to a property of an object associated with the parent PropertyDefinition.

Absolute

The CellEditorPresenter.Path points to a property of PropertyGridControl.SelectedObject.

Example 1: How to display multiple properties in a single row

This example demonstrates a custom template that displays multiple properties in a single PropertyGridControl cell.

Both the absolute and relative paths are specified for the cell editor presenter objects.

How To Edit Multiple Property Values in a Single PropertyGridControl Cell Example

using System;

namespace DXSample {
    public class CategoryAttributesViewModel {
        public virtual Person Person { get; protected set; }
        public CategoryAttributesViewModel() {
            Person = new Person {
                FirstName = "Anita",
                LastName = "Benson",
                Address = new Address {
                    AddressLine1 = "9602 South Main",
                    AddressLine2 = "Seattle, 77025, USA",
                },
                Phone = "7138638137",
            };
        }
    }
    public class Person {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public Address Address { get; set; }
        public string Phone { get; set; }
    }
    public class Address {
        public string AddressLine1 { get; set; }
        public string AddressLine2 { get; set; }
    }
}

Example 2: How to specify a custom editor for CellEditorPresenter

This example demonstrates how to specify a custom editor for CellEditorPresenter associated with the Phone property. For this, create a separate PropertyDefinition for the Phone property and set EditSettings/CellTemplate for it.

CellEditorPresenter Example

<dxprg:PropertyGridControl SelectedObject="{Binding Customer}" ShowProperties="WithPropertyDefinitions">
    <dxprg:PropertyDefinition Path="Name" />
    <dxprg:PropertyDefinition Path="Phone">
        <dxprg:PropertyDefinition.ContentTemplate>
            <DataTemplate>
                <StackPanel>
                    <dxprg:CellEditorPresenter Path="Email" PathMode="Absolute" />
                    <dxprg:CellEditorPresenter Path="Phone" PathMode="Absolute" />
                </StackPanel>
            </DataTemplate>
        </dxprg:PropertyDefinition.ContentTemplate>
    </dxprg:PropertyDefinition>
    <dxprg:PropertyDefinition Path="Email" Visibility="Collapsed">
        <dxprg:PropertyDefinition.EditSettings>
            <dxe:HyperlinkEditSettings AllowAutoNavigate="True" NavigationUrlFormat="mailto:{0}" />
        </dxprg:PropertyDefinition.EditSettings>
    </dxprg:PropertyDefinition>    
</dxprg:PropertyGridControl>
public class Customer {
    public String Name { get; set; }
    public String Email { get; set; }
    public String Phone { get; set; }
}

Headers

The Header is the leftmost element within a PropertyGrid row.

Use the following properties to affect the header.

Member

Characteristics

PropertyDefinitionBase.Header

Content

PropertyDefinitionBase.HeaderShowMode

Position

PropertyDefinitionBase.HeaderTemplate

Template

For example, property definitions below remove [0], [1], etc. headers in collection members and make the Name property header red.

<!--  xmlns:collections="clr-namespace:System.Collections;assembly=mscorlib"  -->
<dxprg:PropertyDefinition Type="{x:Type collections:IList}" TypeMatchMode="Extended">
    <dxprg:PropertyDefinition Header="" />
</dxprg:PropertyDefinition>
<dxprg:PropertyDefinition Header="Name">
    <dxprg:PropertyDefinition.HeaderTemplate>
        <DataTemplate>
            <TextBlock Foreground="Red" Text="{Binding Header}" />
        </DataTemplate>
    </dxprg:PropertyDefinition.HeaderTemplate>
</dxprg:PropertyDefinition>

Description

The Description appears in a tooltip or a panel at the bottom of the Property Grid.

pg_description

Use the following properties to change the description behavior or appearance.

Member

Characteristics

PropertyDefinitionBase.Description

Content

PropertyGridControl.ShowDescriptionIn

Position

PropertyGridControl.DescriptionTemplate

PropertyDefinitionBase.DescriptionTemplate

Template

For example, the following code makes the description text red.

<dxprg:PropertyDefinition Description="Local number" Header="Home number" Path="HomeNumber">
    <dxprg:PropertyDefinition.DescriptionTemplate>
        <DataTemplate>
            <TextBlock Foreground="Red" Text="{Binding}" />
        </DataTemplate>
    </dxprg:PropertyDefinition.DescriptionTemplate>
</dxprg:PropertyDefinition>