I am using Xceed propertygrid in my project, and for some reason when I open the dropdown of the property it is showing "Xceed.Wpf.Toolkit.PropertyGrid.Attributes.Item" instead of the items i inserted. I am sure it is because the toString()
method is called, i just can't figure out why.. I saw this question WPF Xceed PropertyGrid showing "Xceed.Wpf.Toolkit.PropertyGrid.Attributes.Item" instead of the real DisplayName , this is exactly my problem but it doesn't seem that he got a solution. I have tried many attempts solution but non worked. Any suggestions?
You can override the ToString
method to show whatever property you wanted, for example lets say we have the following class as a SelectedObject
for your propertyGrid
control:
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; }
}
the collection should be defined as follow
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;
}
}
and the Employe
class should override the Tostring
method
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>
and the result is what you are looking for
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.