触发时无法显示下划线 [英] Can't get underline to show up when triggered

查看:88
本文介绍了触发时无法显示下划线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有以下样式,但是当鼠标悬停触发器为true时,文本上不会显示下划线。

I have the following style, but when the mouse over trigger is true, no underline shows up on the text.

<Style x:Key="HyperlinkToggleButtonStyle" TargetType="ToggleButton">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="ToggleButton">
                <TextBlock x:Name="TextBlock">
                            <ContentPresenter Content="{TemplateBinding  Content}" ContentTemplate="{TemplateBinding  ContentTemplate}"/>
                </TextBlock>
            </ControlTemplate>
        </Setter.Value>
    </Setter>

    <Style.Triggers>
        <Trigger Property="IsMouseOver" Value="false">
            <Setter Property="Background" Value="{StaticResource StandardBackground}"/>
            <Setter Property="Foreground" Value="Black" />
            <Setter Property="FontSize" Value="12"/>
            <Setter Property="FontStyle" Value="Normal"/>
            <Setter Property="FontWeight" Value="Normal"/>                                         
        </Trigger>

        <Trigger Property="IsMouseOver" Value="true">
            <Setter Property="Background" Value="{StaticResource StandardBackground}"/>
            <Setter Property="Foreground" Value="{StaticResource StandardBlue}" />
            <Setter Property="Cursor" Value="Hand" />
            <Setter Property="FontSize" Value="12"/>
            <Setter Property="FontStyle" Value="Normal"/>
            <Setter Property="FontWeight" Value="Normal"/>
            <Setter Property="TextBlock.TextDecorations" Value="Underline"/>
        </Trigger>
    </Style.Triggers>
</Style>


推荐答案

这可能不是理想的解决方案,但您可以在控制模板中定义触发器。不要忘记在设置器上使用 TargetName 属性引用您的TextBlock。

This might not be an ideal solution, but you could define the trigger in your control template. Don't forget to reference your TextBlock with the TargetName property on the setter.

    <Setter Property="Template">
        <Setter.Value>
           <ControlTemplate TargetType="ToggleButton">
              <TextBlock x:Name="TextBlock">
                        <ContentPresenter Content="{TemplateBinding  Content}" ContentTemplate="{TemplateBinding  ContentTemplate}"/>
              </TextBlock>
              <ControlTemplate.Triggers>
                 <Trigger Property="IsMouseOver" Value="true">
                    <Setter TargetName="TextBlock" Property="TextBlock.TextDecorations" Value="Underline"/>
                 </Trigger>
              </ControlTemplate.Triggers>
           </ControlTemplate>
        </Setter.Value>
     </Setter>

这篇关于触发时无法显示下划线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆