PropertyGrid for WPF | ComponentOne
In This Topic
    Grouping
    In This Topic

    PropertyGrid allows you to combine properties and group them into expandable categories. You can set the category attribute of the properties using Category property of the MemberAttribute class. The Category property specifies the name of the category to group the properties when displayed in the PropertyGrid.

    PropertyGrid with Grouping

    XAML
    Copy Code
             <c1:C1PropertyGrid Margin="130,12,30,12" x:Name="propertyGrid" PropertySort="Categorized" AutoGenerateProperties="False">
                 <c1:C1PropertyGrid.PropertyAttributes>
                   <c1:PropertyAttribute Category="Personal" DisplayName="First Name" MemberName="FirstName"/> 
                   <c1:PropertyAttribute Category="Personal" DisplayName="Last Name" MemberName="LastName"/>
                   <c1:PropertyAttribute Category="Personal" DisplayName="User Name" MemberName="UserName"/>
                   <c1:PropertyAttribute Category="Personal" DisplayName="DOB" MemberName="DOB"/>
                   <c1:PropertyAttribute Category="Login" DisplayName="Email" MemberName="Email"/>
                   <c1:PropertyAttribute Category="Login" DisplayName="Password" MemberName="Password"/>
                 </c1:C1PropertyGrid.PropertyAttributes>
             </c1:C1PropertyGrid>
    

    Back to Top

    Grouping using GroupName Attribute

    In addition to grouping using the Category property, PropertyGrid also allows you to group properties by setting the category group for the properties as demonstrated in the following code.

    C#
    Copy Code
    public partial class Grouping : Window
    {
        public Grouping()
        {
            InitializeComponent();
    
            propertyGrid.SelectedObject = new Persons()
            {
                UserName = "john_241",
                FirstName = "John",
                LastName = "Paul",
                DOB = new DateTime(1987, 2, 23),
                Email = "johnpaul241@gmail.com",
                Password = "john_@109$"
            };
        }
    }
    
    public class Persons
    {
        //Order property for custom sorting
        //GroupName property categorizes the properties in PropertyGrid
    
        [Display(GroupName = "Personal")]
        public string FirstName { get; set; }
        [Display(GroupName = "Personal")]
        public string LastName { get; set; }
        [Display(GroupName = "Personal")]
        public string UserName { get; set; }
        [Display(GroupName = "Personal")]
        public DateTime DOB { get; set; }
        [Display(GroupName = "Login")]
        public string Password { get; set; }
        [Display(GroupName = "Login")]
        public string Email { get; set; }
    }
    

    Back to Top