Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为一个组合框而不是另一个组合框设置ComboBoxItems的样式?_C#_.net_Wpf - Fatal编程技术网

C# 为一个组合框而不是另一个组合框设置ComboBoxItems的样式?

C# 为一个组合框而不是另一个组合框设置ComboBoxItems的样式?,c#,.net,wpf,C#,.net,Wpf,我的风格是这样的: var comboBoxItemStyle = new Style(typeof(ComboBoxItem)); comboBoxItemStyle.Setters.Add(new EventSetter(ComboBoxItem.PreviewMouseDownEvent, new MouseButtonEventHandler(OnMyComboItemMouseDown))); comboBoxItemStyle.S

我的风格是这样的:

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?

当我点击“保存”时,我就明白了

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