【发布时间】:2015-02-24 21:56:03
【问题描述】:
我在这方面做了很多搜索,最终没有答案。
以下是我的一些搜索结果:
Setting combo box foreground color for the disabled state
WPF combobox disabled background color
WPF ComboBox: background color when disabled
有些人说它有效,但有些人说不行。我试过了,我是第一种。
那么究竟如何使它工作呢?我搜索了msdn,答案是复制粘贴标准模板,然后修改。
确定它会起作用,但我只需要更改颜色。这对花生来说太复杂了。
我为自己制作了一个快速的、仅包含 xaml 的程序,但在我的盒子里,它不起作用:
<Window x:Class="WpfApplication11.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<ComboBox Margin="0,0,170,253">
<ComboBox.Style>
<Style TargetType="ComboBox">
<Setter Property="IsEnabled" Value="{Binding IsChecked, ElementName=tgb}"/>
<Style.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Background" Value="#FF000000"/>
</Trigger>
<Trigger Property="IsEnabled" Value="true">
<Setter Property="Background" Value="#FF474747"/>
</Trigger>
</Style.Triggers>
</Style>
</ComboBox.Style>
</ComboBox>
<ToggleButton x:Name="tgb" Margin="347,218,10,10"/>
</Grid>
</Window>
IsEnabled 在切换按钮被点击时切换,当它被禁用时,组合框应该是黑色的,而不是。
最令人困惑的部分是,IsEnabled 为 true 的触发器有效,但为 false 的触发器无效。
有人可以告诉我如何解决这个问题吗?
我现在使用 .net 4.5.1,visual studio 2013。
【问题讨论】:
标签: wpf