[英]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.