当 ComboBox 为只读时,重新设计 ComboBoxI 下拉列表灰色且不可选
我看过这篇文章:WPF ComboBox:禁用时的背景颜色 和其他一些......
但是这个解决方案给我带来了一些问题。我想要的只是将文本框设为灰色,将 ComboBoxItems 设为灰色且不可选择。我不想重新创建所有样式,因为该控件在 XP 和 7 上都无法正常工作。我不想为两者选择一种样式,但我想要为 XP 选择 XP 样式,为 7 种选择 7 种样式。
有没有办法设置样式,以便当组合框为只读时可以更改组合框项目的背景?
提前致谢!
更新:似乎下拉弹出窗口应该重新设计。我必须找到方法。
I have seen this post: WPF ComboBox: background color when disabled
and some others...
But This solution causes me some problems. All I want is to make the textBox gray, and the ComboBoxItems gray and not selectable. I don't want to recreate all the style as the control won't work properly on both XP and seven. I don't want to choose one style for both, but I want XP style for XP and seven style for seven.
Is there a way to set the style so I can change the Background of the ComboBoxItems when the comboBox is Readonly?
Thanks in advance!
Update: It seems that the Drop down popup should be restyled instead. I got to find how.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我终于在网上的很多地方一点一点找到了答案。 ComboBox 样式是由其他控件组成的。 PopUp 是我感兴趣的一个。它不是公开的,所以我无法按照我的意愿修改它。为我的弹出窗口定义一个样式并用它替换原始弹出窗口会很有趣,但它不可访问,所以...我尝试制作一个继承自原始 ComboBox 模板的模板,但那就是也不可能。由于某些充分的原因,它不会接受继承如何继承控件模板 。所以模板要么全部重新制作,要么不重新制作。另一种选择是制作我自己的控件,该控件继承自组合框,并将项目更改为灰色,并且当组合框为只读(进入代码)时不可选择,但这在我的情况下不是一个好主意。对我来说没有解决方案。我将不得不坚持整个模板的重新定义。我希望这篇文章能以某种方式帮助某人!
I finally found my answer at many places on the web, pieces by pieces. The ComboBox style is composed of other controls. The PopUp is the one that interests me. It is not public, so I can't modify it as I want. It would have been interesting to define a style for my popup and to replace the original popup by it, but it is not accessible, so... I attempted to make a template that inherits from the template of the original ComboBox, but that is not possible neither. It won't accept inheritance for some good reasons How to Inherit a Control Template. So the template must be remade totally or not. The other option would be to make my own control that inherits from combobox and that changes the items to gray and not selectable when the combobox is readonly (into the code), but this is not a good idea in my situation. No solution for me. I will have to stick with the whole template redifinition. I hope this post will help someone in some way!