1

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 を使用しています。

私はいくつかのことを試しましたが、アイデアがありません。どんな助けでも大歓迎です。

4

1 に答える 1

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;
}
于 2015-03-03T18:33:03.333 に答える