更改 WPF 数据绑定组合框中分隔符的背景颜色
我有一个绑定到数据集的组合框,然后在数据中遇到“-”时使用数据触发器插入分隔符(示例 在此问题中)。
菜单的背景具有自定义颜色,通过使用资源字典设置。本例中的颜色是 #FFF8F4C5
如果我将分隔符添加到非数据绑定简单组合框,它会正确显示。但是,当使用数据触发器添加它时,它看起来不像菜单的其余部分,如下所示(它有白色背景)。
如果我设置分隔符的背景,它实际上会将较暗的线条更改为任何颜色。我似乎找不到如何更改白色区域以匹配与菜单相同的颜色。
I have a combobox that is bound to a dataset that then uses a datatrigger to insert a separator when it encounters a '-' in the data (example in this question).
The background of the menu has custom color, set by using a resource dictionary. The color in this case is #FFF8F4C5
If I add a separator to a non databound simple combo box, it appears correctly. But when adding it using the datatrigger, it does not look like the rest of the menu, as you can see below (it has a white background).
If I set the background of the separator, it actually changes the darker line to whatever color. I can't seem to find how to change the white area to match the same color as the menu.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 ControlTemplate 中,将分隔符包含在边框中,并将背景绑定到父 ComboBoxItem 的背景。像这样的东西:
In the ControlTemplate, enclose the Separator in a Border with Background bound to to the parent ComboBoxItem's Background. Something like this:
使用分隔符样式:
并像这样使用
它应该可以做到
use a separator style:
and use it like this
That should do it