如何在 MouseEnter 上的 TextBlock 下划线 [英] How to underline a TextBlock on a MouseEnter

查看:30
本文介绍了如何在 MouseEnter 上的 TextBlock 下划线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 WPF 表单中,我有以下 TextBlock.当我将鼠标移到它上面时,我希望看到带下划线的 TextBlock 的文本.我怎样才能做到这一点?我尝试使用 TextBlock.Triggers,但没有奏效.

In a WPF form, I have the following TextBlock. When I move my mouse over it, I would like to see the text of the TextBlock underlined. How can I do that? I tried with TextBlock.Triggers, but it didn't work.

谢谢!

推荐答案

使用样式:

<TextBlock Text="Hurrah">
  <TextBlock.Style>
    <Style TargetType="TextBlock">
      <Style.Triggers>
        <Trigger Property="IsMouseOver" Value="True">
          <Setter Property="TextDecorations" Value="Underline" />
        </Trigger>
      </Style.Triggers>
    </Style>
  </TextBlock.Style>
</TextBlock>

(为简洁起见,样式显示为内联;如果您打算重复使用,请提取到资源中.)

(Style shown inline for brevity; extract into a resource if you're planning to reuse it.)

这篇关于如何在 MouseEnter 上的 TextBlock 下划线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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