Wpf 中 ToggleButton 仅在 IsChecked = False 时触发 OnMouseOver
Trigger OnMouseOver only when IsChecked = False for ToggleButton in Wpf
我设置了 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>
我设置了 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>