仅当 WPF 中的切换按钮为 IsChecked = False 时触发鼠标悬停



>我设置了一个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>

相关内容

  • 没有找到相关文章

最新更新