1

UI 項目を表示するために、 WPFプロジェクトでプロパティ グリッドを使用しています。したがって、基本的にコレクション型のプロパティには、comboBox が必要です。この目的のために、Extended PropertyValueEditor を使用しています。問題は、コレクションごとに [言語、オペレーティング システム、またはその他のコレクションなど...] ItemsSource がそれぞれ異なるため、個別のコンボ ボックス エディターを作成する必要があることです。ジェネリックコンボ ボックスを作成し、コレクションの種類に応じてそのItemsSourceプロパティを設定する方法はありますか。(言語またはオペレーティング システムのコレクションを返す特定の関数のセットがあるとします)

PS:表示する膨大な数のコレクションがあります。他のアプローチも高く評価されます!!!

以下のサンプル コードを参照してください。

これは、オペレーティング システム コレクションのエディターです。

public class OperatingSystemsEditor : ExtendedPropertyValueEditor
    {
        public OperatingSystemsEditor()
        {
            DataTemplate customTemplate = new DataTemplate();

            FrameworkElementFactory comboBox = new     FrameworkElementFactory(typeof (ComboBox));
            LanguageParser utilObj = new LanguageParser();

            comboBox.SetValue(ComboBox.ItemsSourceProperty, utilObj.GetOperatingSystemsAll());

            Binding selectedItem = new Binding("Value");
            comboBox.SetValue(ComboBox.SelectedItemProperty, selectedItem);
            selectedItem.Mode = BindingMode.TwoWay;

            this.InlineEditorTemplate = customTemplate;
            this.InlineEditorTemplate.VisualTree = comboBox;
        }
    }

これは Languages コレクションのエディターです

public class LanguagesEditor : ExtendedPropertyValueEditor
    {
        public LanguagesEditor()
        {
            DataTemplate customTemplate = new DataTemplate();

            FrameworkElementFactory comboBox = new FrameworkElementFactory(typeof(ComboBox));
            LanguageParser utilObj = new LanguageParser();

            comboBox.SetValue(ComboBox.ItemsSourceProperty, utilObj.GetLanguagesAll());

            Binding selectedItems = new Binding("Value");
            comboBox.SetValue(ComboBox.SelectedItemProperty, selectedItems);
            selectedItems.Mode = BindingMode.TwoWay;

            this.InlineEditorTemplate = customTemplate;
            this.InlineEditorTemplate.VisualTree = comboBox;
        }
    }

これらのエディターをどのように利用しているか:

[Editor(typeof(LanguagesEditor), typeof(ExtendedPropertyValueEditor))]
public ObservableCollection<>Languages
{get; set;}

[Editor(typeof(OperatingSystemsEditor), typeof(ExtendedPropertyValueEditor))]
public ObservableCollection<> OperatingSystems
{get; set;}
4

0 に答える 0