仅当Wpf中的ToggleButton的IsChecked = False时触发OnMouseOver

时间:2015-01-06 23:25:57

标签: wpf triggers styles onmouseover togglebutton

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

1 个答案:

答案 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>