我在我的项目中使用了Xceed property using,由于某种原因,当我打开属性的下拉列表时,它显示的是"Xceed.Wpf.Toolkit.PropertyGrid.Attributes.Item“而不是我插入的项。我敢肯定是因为调用了toString()方法,我就是不明白为什么..我看到了这个问题,WPF Xceed PropertyGrid showing "Xceed.Wpf.Toolkit.PropertyGrid.Attributes.Item" instead of the real DisplayName,这正是我的问题,但他似乎没有得到解决方案。我已经尝试了很多次解决方案,但都不起作用。有什么建议吗?
发布于 2015-08-18 08:10:59
您可以重写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>结果就是你想要的结果

https://stackoverflow.com/questions/32053226
复制相似问题