我设置了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>
答案 0 :(得分:1)
另一个触发器应该这样做:
<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>