2

私は次のようなスタイルを持っています:

var comboBoxItemStyle = new Style(typeof(ComboBoxItem));
comboBoxItemStyle.Setters.Add(new EventSetter(ComboBoxItem.PreviewMouseDownEvent,
                          new MouseButtonEventHandler(OnMyComboItemMouseDown)));

comboBoxItemStyle.Setters.Add(new EventSetter(ComboBoxItem.PreviewKeyDownEvent, 
                          new KeyEventHandler(OnMyComboItemPreviewKeyDown)));

私が次にすることはこれです:

Resources.Add(typeof(ComboBoxItem), comboBoxItemStyle);

しかし、それはすべてのコンボボックスにこのスタイルを追加します。

2つのComboBoxがあるとします。

 ComboBox myComboBox = new ComboBox();
 ComboBox someOneElsesComboBox = new ComboBox();

このスタイルをに適用するにはどうすればよいMyComboBoxですか?

4

1 に答える 1

3

「保存」を押すとわかりました

myComboBox.Resources.Add(typeof(ComboBoxItem), comboBoxItemStyle);
于 2013-01-22T23:28:47.897 に答える