gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 22:21:18 29 4
gpt4 key购买 nike

我有一个看起来像这样的样式:

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

关于c# - 为一个组合框而不是另一个组合框设置 ComboBoxItems 的样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14469890/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com