Back to Devexpress

Descriptions

wpf-117200-controls-and-libraries-property-grid-descriptions.md

latest6.4 KB
Original Source

Descriptions

  • Dec 16, 2019
  • 3 minutes to read

Overview

The PropertyGrid control can display extra information about the properties of a bound object in the form of property descriptions. You can specify property descriptions in the following ways.

Depending on the PropertyGridControl.ShowDescriptionIn property value, the property grid displays property descriptions in the following ways.

|

ShowDescriptionIn

property value

|

Property descriptions position

| | --- | --- | |

None

|

Descriptions are disabled.

| |

Panel

|

The description panel.

| |

ToolTip

|

A description tooltip.

| |

ToolTipAndPanel

|

Both the description panel and description tooltip.

|

Specifying Property Descriptions at the Control Level

The PropertyGrid control allows you to specify a custom description for each of the following elements.

  • Properties
  • Collections
  • Category rows

Descriptions are specified for individual definitions by the PropertyDefinitionBase.Description property. This approach allows you to assign property descriptions by using the association criteria described in the Property Definitions topic.

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

  • Both the description panel and the tooltip display the description text.

  • All string properties have similar description specified.

  • Nested Address property definitions override the description text.

  • XAML

  • C#

xaml
<Window.DataContext>
    <local:ViewModel/>
</Window.DataContext>
...
<dxprg:PropertyGridControl SelectedObject="{Binding Data}" ShowProperties="WithPropertyDefinitions" ShowDescriptionIn="ToolTipAndPanel">
    <dxprg:PropertyDefinition Type="sys:String" Description="A string property"/>
    <dxprg:PropertyDefinition Type="{x:Type local:SimpleAddress}" Description="Customer's address">
        <dxprg:PropertyDefinition Path="*" Description="Address details"/>
        <dxprg:PropertyDefinition Path="ZIP" Description="Customer's postal code"/>
    </dxprg:PropertyDefinition>            
</dxprg:PropertyGridControl>
csharp
using System.ComponentModel;
...
public class SimpleModel {
    public int ID { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    [TypeConverter(typeof(ExpandableObjectConverter))]
    public SimpleAddress Address { get; set; }
}

public class SimpleAddress {
    public string State { get; set; }
    public string City { get; set; }
    public string ZIP { get; set; }
}

public class ViewModel {
    public SimpleModel Data { get; set; }
    public ViewModel() {
        Data = new SimpleModel {
            ID = 0,
            FirstName = "Anna",
            LastName = "Trujilo",
            Address = new SimpleAddress() {State="California", City="Oakland", ZIP="94601"}
        };
    }
}

Note

To learn more about nested properties, refer to the Nested properties section of the Property Definitions topic.

Specifying Property Descriptions at the Model Level

To specify property descriptions at the model level, use the Description attribute.

The Description attribute allows you to specify descriptions for the following elements.

  • Properties
  • Collections

Note

Descriptions specified by the PropertyDefinitionBase.Description property override the description attribute values.

Note

To learn more about the property attributes supported by the PropertyGrid control, see Property Attributes.

The following example demonstrates the property descriptions defined with the Description attribute.

xaml
<Window.DataContext>
    <local:ViewModel/>
</Window.DataContext>
...
<dxprg:PropertyGridControl SelectedObject="{Binding Data}" ShowProperties="WithPropertyDefinitions" ShowDescriptionIn="ToolTipAndPanel">
    <dxprg:PropertyDefinition Type="sys:String" />
    <dxprg:PropertyDefinition Type="{x:Type local:SimpleAddress}" >
        <dxprg:PropertyDefinition Path="*" />
        <dxprg:PropertyDefinition Path="ZIP"/>
    </dxprg:PropertyDefinition>
</dxprg:PropertyGridControl>
csharp
using System.ComponentModel;   
...
public class SimpleModel {
    public int ID { get; set; }
    [Description("Customer's first name")]
    public string FirstName { get; set; }
    [Description("Customer's last name")]
    public string LastName { get; set; }
    [TypeConverter(typeof(ExpandableObjectConverter)), Description("Customer's address")]
    public SimpleAddress Address { get; set; }
}

public class SimpleAddress {
    public string State { get; set; }
    public string City { get; set; }
    [Description("Customer's postal code")]
    public string ZIP { get; set; }
}

public class ViewModel {
    public SimpleModel Data { get; set; }
    public ViewModel() {
        Data = new SimpleModel {
            ID = 0,
            FirstName = "Anna",
            LastName = "Trujilo",
            Address = new SimpleAddress() {State="California", City="Oakland", ZIP="94601"}
        };
    }
}

See Also

Property Definitions

Collection Definitions

Property Categories

Property Attributes