簡體   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