[英]WPF Xceed PropertyGrid showing “Xceed.Wpf.Toolkit.PropertyGrid.Attributes.Item” instead of the real DisplayName
我正在尝试使用Xceed PropertyGrid显示带有硬编码字符串值的下拉列表。 而不是将项目显示为我分配为IItemSource
的字符串,PropertyGrid为下拉列表中的每个项目显示:“ 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,顺便说一句。
我已经尝试了好几件事,但是没有主意。 任何帮助表示赞赏。
这应该工作:
public ItemCollection GetValues()
{
var printers = new ItemCollection();
for (int i = 0; i < 7; i++)
{
string entry = "Option - " + i;
printers.Add(entry, entry);
}
return printers;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.