您可以重写 ToString 方法来显示您想要的任何属性,例如,假设我们有以下类作为您的 propertyGrid 控件的 SelectedObject:
public class Company
{
[Category("Main")]
[DisplayName("Name")]
[Description("Property description")]
public String Name { get; set; }
[Category("Main")]
[DisplayName("Type")]
[Description("Property description")]
public String Type { get; set; }
[Category("Main")]
[DisplayName("Something")]
[Description("Property description")]
public bool Something { get; set; }
[Category("Main")]
[DisplayName("Director")]
[Description("Property description")]
[ItemsSource(typeof(EmployeList))]
public Employe Director { get; set; }
}
集合应该定义如下
public class EmployeList : IItemsSource
{
public Xceed.Wpf.Toolkit.PropertyGrid.Attributes.ItemCollection GetValues()
{
Xceed.Wpf.Toolkit.PropertyGrid.Attributes.ItemCollection employe = new Xceed.Wpf.Toolkit.PropertyGrid.Attributes.ItemCollection();
employe.Add(new Employe()
{
Name = "Name1",
Rank = "Rank1",
Age=40,
}); employe.Add(new Employe()
{
Name = "Name2",
Rank = "Rank2",
Age=40,
}); employe.Add(new Employe()
{
Name = "Name3",
Rank = "Rank3",
Age=40,
});
return employe;
}
}
并且Employe 类应该覆盖Tostring 方法
public class Employe
{
public String Name { get; set; }
public String Rank { get; set; }
public int Age { get; set; }
public override string ToString()
{
return Name;
}
}
xaml
<xctk:PropertyGrid Name="pg" SelectedObject="{Binding SelectedCompany}" AutoGenerateProperties="True" >
</xctk:PropertyGrid>
结果就是你要找的东西