Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WPF Xceed PropertyGrid显示;Xceed.Wpf.Toolkit.PropertyGrid.Attributes.Item";而不是真实的显示名_C#_Wpf_Caliburn.micro_Propertygrid_Xceed - Fatal编程技术网

C# WPF Xceed PropertyGrid显示;Xceed.Wpf.Toolkit.PropertyGrid.Attributes.Item";而不是真实的显示名

C# WPF Xceed PropertyGrid显示;Xceed.Wpf.Toolkit.PropertyGrid.Attributes.Item";而不是真实的显示名,c#,wpf,caliburn.micro,propertygrid,xceed,C#,Wpf,Caliburn.micro,Propertygrid,Xceed,我试图使用Xceed PropertyGrid来显示带有硬编码字符串值的下拉列表。 PropertyGrid显示的不是我指定为IItemSource的字符串,而是下拉列表中每个项目的“Xceed.Wpf.Toolkit.PropertyGrid.Attributes.Item”。 当我选择一个对象时,所需的字符串显示为所选项目 这是我看到的下拉项: 当我选择一个项目时,我可以以我希望它显示为下拉项目的方式查看它: 我的代码: XAML: C#: [可序列化] 公共类设置振打器 { [本地

我试图使用Xceed PropertyGrid来显示带有硬编码字符串值的下拉列表。 PropertyGrid显示的不是我指定为
IItemSource
的字符串,而是下拉列表中每个项目的“Xceed.Wpf.Toolkit.PropertyGrid.Attributes.Item”。 当我选择一个对象时,所需的字符串显示为所选项目

这是我看到的下拉项:

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

我的代码:

XAML:


C#:

[可序列化]
公共类设置振打器
{
[本地化分类(“设置视图分类硬件”)]
[本地化显示名称(“设置查看选择打印机”)]
[ItemsSource(typeof(PrintersItemSource))]
公共字符串SelectedPrinter{get;set;}
公共类PrintersItemSource:IItemsSource
{
public ItemCollection GetValues()
{
var printers=new ItemCollection();
对于(int i=0;i<7;i++)
{
打印机。添加(“选项-”+i);
}
返回打印机;
}
}
}
我用的是Caliburn.Micro,顺便说一句

我试过好几件事,但都没有主意了。 非常感谢您的帮助。

这应该可以:

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

    return printers;
}
public ItemCollection GetValues()
{
var printers=new ItemCollection();
对于(int i=0;i<7;i++)
{
string entry=“Option-”+i;
打印机。添加(条目,条目);
}
返回打印机;
}

实际上,这两种方法的工作方式应该与“Add”函数中对象的“ToString()”的工作方式相同。所以这是一个模板问题。当没有为给定类型设置或找到模板时,它会打印绑定对象的“ToString()”。在您的例子中,“Xceed.Wpf.Toolkit.PropertyGrid.Attributes.Item”。顺便说一句,它在我这边工作得很好。是的,我注意到在没有发送
DisplayName
参数的情况下,toString()会后退。。但是我不知道我做错了什么..您是否可以给我发送一个快速而简单的VisualStudio解决方案来解决这个问题?这样,我就可以在我这边测试它了。
[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;
        }
    }
}
public ItemCollection GetValues()
{
    var printers = new ItemCollection();
    for (int i = 0; i < 7; i++)
    {
        string entry = "Option - " + i;
        printers.Add(entry, entry);
    }

    return printers;
}