本文介绍了WPF Xceed PropertyGrid显示"Xceed.Wpf.Toolkit.PropertyGrid.Attributes.Item";而不是真实的DisplayName的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Xceed PropertyGrid显示带有硬编码字符串值的下拉列表.PropertyGrid没有显示项目,而是显示我分配为IItemSource的字符串,而是显示下拉列表中每个项目的"Xceed.Wpf.Toolkit.PropertyGrid.Attributes.Item".当我选择一个对象时,所需的字符串将显示为所选项目.

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.

这是我看到的下拉项:

当我选择一个项目时,我也可以按照我希望其作为下拉项目显示的方式来查看它:

And when I choose an item, I can see it the way I want it to appear as the dropdown items as well:

我的代码:

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

我正在使用Caliburn.Micro,顺便说一句.

I'm using Caliburn.Micro, BTW.

我尝试了几件事,但没有主意.感谢您的帮助.

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

推荐答案

这应该有效:

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

    return printers;
}

这篇关于WPF Xceed PropertyGrid显示"Xceed.Wpf.Toolkit.PropertyGrid.Attributes.Item";而不是真实的DisplayName的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 17:41