简体   繁体   中英

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. 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.

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

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.

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