禁用列表框不会改变样式中的背景颜色
我有这种简单的样式,当禁用 ListBox
时,它不会更改 ListBox
Background
:
<Style TargetType="ListBox" >
<Style.Triggers>
<Trigger Property="IsEnabled" Value="True">
<Setter Property="Background" Value="Red"/>
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Background" Value="Orange"/>
</Trigger>
</Style.Triggers>
</Style>
Snoop 在这方面没有帮助我,我不能想出一种无需重写模板的简单方法。有人有一个简单的方法来让它工作吗? TIA。
I have this simple style that does not change the ListBox
Background
when the ListBox
is disabled:
<Style TargetType="ListBox" >
<Style.Triggers>
<Trigger Property="IsEnabled" Value="True">
<Setter Property="Background" Value="Red"/>
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Background" Value="Orange"/>
</Trigger>
</Style.Triggers>
</Style>
Snoop does not help me on this one and I cannot figure a simple way without overriding templates. Anyone have a simple way to get this working? TIA.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
做到这一点的唯一方法是覆盖模板
The only way to do this is by overriding the template
当列表框被禁用时,您可以通过简单地更改内置模板正在使用的颜色来更改列表框本身的背景颜色。您可以通过样式资源来做到这一点。只需将以下代码粘贴到列表框元素中,当您禁用该框时,背景将是透明的。
当单个项目突出显示时以及当框失去焦点时想要修改其背景颜色也是很常见的。要更改这些,您可以参考这篇文章:
https://stackoverflow.com/a/7298301/1721136
You can change the background color of the listbox itself when the listbox is disabled by simply changing the colors that the built-in template is using. You can do this via style resources. Just paste the below code into your Listbox element and the background will be transparent when you disable the box.
It is also very common to want to modify the background color of a single item when it's highlighted and when the box loses focus.. to change these, you can reference this post:
https://stackoverflow.com/a/7298301/1721136