我的风格如下:
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();
如何将此款式仅应用于MyComboBox
?
答案 0 :(得分:3)
当我点击“保存”时想出来
myComboBox.Resources.Add(typeof(ComboBoxItem), comboBoxItemStyle);