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.
XAML |
コードのコピー
|
---|---|
<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> |
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# |
コードのコピー
|
---|---|
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 プロパティ //GroupName プロパティは 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; } } |