选中ToggleButton后,应将按钮设置为disabled,并且应更改前景颜色。以下代码不起作用:
<Window x:Class="WpfApplication1.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>
<ToggleButton Content="Hallo" Margin="113,97,72,46" >
<ToggleButton.Style>
<Style TargetType="{x:Type ToggleButton}">
<Setter Property="Foreground" Value="Blue"/>
<Setter Property="IsEnabled" Value="True"/>
<Setter Property="IsChecked" Value="False"/>
<Style.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter Property="IsEnabled" Value="False"/>
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" Value="Green"/>
</Trigger>
</Style.Triggers>
</Style>
</ToggleButton.Style>
</ToggleButton>
</Grid>
我该怎么做呢?
发布于 2015-09-02 08:25:48
禁用控件的外观在不同的windows版本和不同的Windows帐户设置等方面是不同的,这就是为什么它适用于其他人而不是您。一般来说,您应该遵守这些设置,但是如果您确实很坚持,那么您将需要显式地覆盖模板,如this question中所示
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Grid Background="{TemplateBinding Background}">
<ContentPresenter x:Name="MyContentPresenter" Content="{TemplateBinding Content}"
HorizontalAlignment="Center"
VerticalAlignment="Center" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>https://stackoverflow.com/questions/32338180
复制相似问题