Extended Library for WPF and Silverlight | ComponentOne
In This Topic
    Categorizing Properties
    In This Topic

     

    You can group properties by category by adding a Category attribute to each property on the object being browsed (note that the Category attribute is defined in the System.ComponentModel namespace, in the System.Windows assembly). By default the members in the list will be listed alphabetically and uncategorized. By adding categories you can better organize members by listing related members together.

    Continuing with our example, here's a revised version of the Customer class which includes categories:

    Visual Basic
    Copy Code
    Public Class Customer
    Private _Name As String
        <Category("Contact")> _
        <DisplayName("Customer Name")> _
        Public Property Name() As String
            Get
                Return _Name
            End Get
            Set(ByVal value As String)
                _Name = value
            End Set
        End Property
       
    Private _EMail As String
        <Category("Contact")> _
        <DisplayName("e-Mail address")> _
        Public Property EMail() As String
            Get
                Return _EMail
            End Get
            Set(ByVal value As String)
                _EMail = value
            End Set
        End Property
       
    Private _Address As String
        <Category("Contact")> _
        Public Property Address() As String
            Get
                Return _Address
            End Get
            Set(ByVal value As String)
                _Address = value
            End Set
        End Property
       
    Private _CustomerSince As DateTime
        <Category("History")> _
        <DisplayName("Customer Since")> _
        Public Property CustomerSince() As DateTime
            Get
                Return _CustomerSince
            End Get
            Set(ByVal value As DateTime)
                _CustomerSince = value
            End Set
        End Property
       
    Private _SendNewsletter As Boolean
        <Category("Contact")> _
        <DisplayName("Send Newsletter")> _
        Public Property SendNewsletter() As Boolean
            Get
                Return _SendNewsletter
            End Get
            Set(ByVal value As Boolean)
                _SendNewsletter = value
            End Set
        End Property
       
    Private _PointBalance As System.Nullable(Of Integer)
        <Category("History")> _
        <DisplayName("Point Balance")> _
        Public Property PointBalance() As System.Nullable(Of Integer)
            Get
                Return _PointBalance
            End Get
            Set(ByVal value As System.Nullable(Of Integer))
                _PointBalance = value
            End Set
        End Property
    End Class
    

    C#
    Copy Code
    public class Customer
    {
      [Category("Contact")]
      [DisplayName("Customer Name")]
      public string Name { get; set; }
    
      [Category("Contact")]
      [DisplayName("e-Mail address")]
      public string EMail { get; set; }
    
      [Category("Contact")]
      public string Address { get; set; }
    
      [Category("History")]
      [DisplayName("Customer Since")]
      public DateTime CustomerSince { get; set; }
    
      [Category("Contact")]
      [DisplayName("Send Newsletter")]
      public bool SendNewsletter { get; set; }
    
      [Category("History")]
      [DisplayName("Point Balance")]
      public int? PointBalance { get; set; }
    }
    

     

    And here is the result of this change:

     

     

    Notice how properties are neatly grouped by category. Each group can be expanded and collapsed, making it easier for the user to find specific properties.

    You can also use the C1PropertyGrid.DefaultCategoryName property to set the name of a default category which will contain all the properties that have no other category defined.