我有一个看起来像这样的风格:
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
?