Skip to main content
A newer version of this page is available. .

Property Attributes

  • 2 minutes to read

The PropertyGrid control recognizes property attributes specified in the model.

Property attributes allow you to configure the appearance and behavior of the PropertyGrid control on the model level. To use property atributes in your project, reference the System.ComponentModel namespace.

The following example demonstrates the property attribute syntax.

using System.ComponentModel;
...
[TypeConverter(typeof(ExpandableObjectConverter)), Description("Customer's address")]
public SimpleAddress Address { get; set; }

The following table lists some of the property attributes recognized by the PropertyGrid control.

Attribute

Description

BrowsableAttribute

Specifies whether the property is displayed within the property grid.

CategoryAttribute

Specifies the property’s category.

To learn more, see Property Categories.

DefaultValueAttribute

Specifies the property’s default value.

DescriptionAttribute

Specifies the property’s description.

To learn more, see Property descriptions.

DisplayNameAttribute

Specifies the property’s display name.

ReadOnlyAttribute

Specifies whether the property is read-only.

TypeConverterAttribute

Specifies a type converter for the property.

To learn more, see Expandability Customization.

InstanceInitializerAttribute

Specifies an instance initializer for the property.

To learn more, see Collection Definitions.

The following example demonstrates the use of various property attributes.

using System.Collections.Generic;
using System.ComponentModel;
...
public class Customer {
    [Browsable(false), ReadOnly(true)]
    public int ID { get; set; }
    [Category("Customer Info"), Description("Customer's full name")]
    public string Name { get; set; }
    [Category("Contact"), Description("Customer's email address")]
    public string Email { get; set; }
    [Category("Contact"), Description("Customer's phone number")]
    public string Phone { get; set; }
    [Category("Order Info"), Description("Ordered items"), DisplayName("Ordered Items")]
    public ProductList Products { get; set; }
}

public class Book {
    [DisplayName("ISBN")]
    public int ID { get; set; }
    public string Author { get; set; }
    public string Title { get; set; }
    public double Price { get; set; }
}

public class ProductList : List<Object> {
    public ProductList() : base() { }
    public override string ToString() {
        return "Product List";
    }
}
public class ViewModel {
    public Customer DemoCustomer { get; set; }
    public ViewModel() {
        DemoCustomer = new Customer()
        {
            ID = 0,
            Name = "Anita Benson",
            Email = "Anita_Benson@example.com",
            Phone = "7138638137",
            Products = new ProductList {
                new Book
                {
                    ID = 47583,
                    Author = "Arthur Cane",
                    Title = "Digging deeper",
                    Price = 14.79
                }
            }
        };
    }
}
...
<Window.DataContext>
    <local:ViewModel/>
</Window.DataContext>
...
<dxprg:PropertyGridControl SelectedObject="{Binding DemoCustomer}"/>

PG_Attributes

See Also