简体   繁体   English

WPF Xceed PropertyGrid显示“ Xceed.Wpf.Toolkit.PropertyGrid.Attributes.Item”,而不是实际的DisplayName

[英]WPF Xceed PropertyGrid showing “Xceed.Wpf.Toolkit.PropertyGrid.Attributes.Item” instead of the real DisplayName

I'm trying to use Xceed PropertyGrid to show dropdown with hardcoded string values. 我正在尝试使用Xceed PropertyGrid显示带有硬编码字符串值的下拉列表。 Instead of showing the items as the strings I assign as the IItemSource , PropertyGrid showing: "Xceed.Wpf.Toolkit.PropertyGrid.Attributes.Item" for each item in the dropdown. 而不是将项目显示为我分配为IItemSource的字符串,PropertyGrid为下拉列表中的每个项目显示:“ Xceed.Wpf.Toolkit.PropertyGrid.Attributes.Item”。 When I select an object, the desired string is showing as the chosen item. 当我选择一个对象时,所需的字符串将显示为所选项目。

This is the dropdown items I see: 这是我看到的下拉项:

在此处输入图片说明

And when I choose an item, I can see it the way I want it to appear as the dropdown items as well: 当我选择一个项目时,我也可以按照我希望它作为下拉项目出现的方式来查看它:

在此处输入图片说明

My code: 我的代码:

XAML: XAML:

<xctk:PropertyGrid SelectedObject="{Binding MySettingsWrapper}" AutoGenerateProperties="True">
</xctk:PropertyGrid>

C#: C#:

[Serializable]
public class SettingsWrapper
{
    [LocalizedCategory("SettingsViewCategoryHardware")]
    [LocalizedDisplayName("SettingsViewLblSelectPrinter")]
    [ItemsSource(typeof(PrintersItemSource))]
    public string SelectedPrinter { get; set; }

    public class PrintersItemSource : IItemsSource
    {
        public ItemCollection GetValues()
        {
            var printers = new ItemCollection();
            for (int i = 0; i < 7; i++)
            {
                printers.Add("Option - " + i);
            }

            return printers;
        }
    }
}

I'm using Caliburn.Micro, BTW. 我正在使用Caliburn.Micro,顺便说一句。

I've tried several things and I'm out of ideas. 我已经尝试了好几件事,但是没有主意。 Any help is appreciated. 任何帮助表示赞赏。

This should work: 这应该工作:

public ItemCollection GetValues()
{
    var printers = new ItemCollection();
    for (int i = 0; i < 7; i++)
    {
        string entry = "Option - " + i;
        printers.Add(entry, entry);
    }

    return printers;
}

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

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