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

戏子无情 提交于 2019-12-13 00:39:16

问题


I'm trying to use Xceed PropertyGrid to show dropdown with hardcoded string values. 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. 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:

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

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.

I've tried several things and I'm out of ideas. Any help is appreciated.


回答1:


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;
}


来源:https://stackoverflow.com/questions/28836989/wpf-xceed-propertygrid-showing-xceed-wpf-toolkit-propertygrid-attributes-item

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!