【问题标题】:WPF Xceed PropertyGrid showing "Xceed.Wpf.Toolkit.PropertyGrid.Attributes.Item" instead of the real DisplayNameWPF Xceed PropertyGrid 显示“Xceed.Wpf.Toolkit.PropertyGrid.Attributes.Item”而不是真实的 DisplayName
【发布时间】:2023-04-04 04:15:02
【问题描述】:

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

这是我看到的下拉项:

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

我的代码:

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,顺便说一句。

我已经尝试了几件事,但我没有想法。 任何帮助表示赞赏。

【问题讨论】:

    标签: c# wpf caliburn.micro propertygrid xceed


    【解决方案1】:

    这应该可行:

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

    【讨论】:

    • 确实,两者都应该像您在“添加”函数中的对象的“ToString()”一样工作。所以这是一个模板问题。当没有为给定类型设置或找到模板时,它会打印绑定对象的“ToString()”。在您的情况下,“Xceed.Wpf.Toolkit.PropertyGrid.Attributes.Item”。顺便说一句,它在我这边工作正常。
    • 是的,我注意到 toString() 回退,以防没有发送 DisplayName 参数。虽然不知道我做错了什么..
    • 您是否可以向我发送一个快速而肮脏的简单 Visual Studio 解决方案来解决问题?这样一来,我就可以在我这边进行测试了。
    猜你喜欢
    • 1970-01-01
    • 2016-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-24
    • 1970-01-01
    相关资源
    最近更新 更多