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);

但这会将这种样式添加到所有组合框。

假设我有两个组合框:

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

我怎样才能将这种风格应用于 just MyComboBox

4

1 回答 1

3

当我点击“保存”时想通了

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