繁体   English   中英

Xceed propertygrid不显示DisplayName

[英]Xceed propertygrid not showing DisplayName

我在项目中使用Xceed propertygrid,由于某种原因,当我打开该属性的下拉菜单时,它显示的是“ Xceed.Wpf.Toolkit.PropertyGrid.Attributes.Item”,而不是我插入的项目。 我相信这是因为toString()方法被调用时,我只是想不通为什么..我看到这个问题WPF Xceed PropertyGrid中显示“Xceed.Wpf.Toolkit.PropertyGrid.Attributes.Item”,而不是真正的显示名称的 ,这正是我的问题,但似乎他没有找到解决方案。 我尝试了许多尝试解决方案,但没有用。 有什么建议么?

您可以重写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;
    }
}

a

<xctk:PropertyGrid  Name="pg"  SelectedObject="{Binding SelectedCompany}" AutoGenerateProperties="True" >                
    </xctk:PropertyGrid>

结果就是您想要的

输出

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM