>我设置了一个ToggleButton
样式,以便当鼠标悬停在它上面时,会出现一个Underline
。但是,如果我希望此下划线仅在IsChecked = False
时才出现呢?我不希望在IsChecked = True
时出现下划线.
<Style x:Key="BaseToggleButton" TargetType="ToggleButton">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToggleButton">
<TextBlock x:Name="Content">
<ContentPresenter/>
</TextBlock>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Content" Property="TextBlock.TextDecorations" Value="Underline"/>
</Trigger>
<Trigger Property="IsChecked" Value="False">
</Trigger>
<Trigger Property="IsChecked" Value="True">
<Setter TargetName="Content" Property="Background" Value="#acacac"/>
<Setter TargetName="Content" Property="TextBlock.Foreground" Value="Black"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
另一个触发器应该这样做:
<Style x:Key="BaseToggleButton" TargetType="ToggleButton">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToggleButton">
<TextBlock x:Name="Content">
<ContentPresenter/>
</TextBlock>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Content" Property="TextBlock.TextDecorations" Value="Underline"/>
</Trigger>
<Trigger Property="IsChecked" Value="True">
<Setter TargetName="Content" Property="TextBlock.TextDecorations" Value="None"/>
</Trigger>
<Trigger Property="IsChecked" Value="False">
</Trigger>
<Trigger Property="IsChecked" Value="True">
<Setter TargetName="Content" Property="Background" Value="#acacac"/>
<Setter TargetName="Content" Property="TextBlock.Foreground" Value="Black"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>