WPF TextBlock的样式下划线鼠标悬停 [英] WPF TextBlock Style Underline on Mouse Hover

查看:1381
本文介绍了WPF TextBlock的样式下划线鼠标悬停的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简单的问题。以下WPF C#代码可以减少一些体重?我的意思是,跆拳道,呃...我的意思是WPF,再来一个。你每一个见过CSS?我只希望当我用鼠标就像一个链接悬停强调文本。 ?难道我真的要增加9条线为

Simple question. Can the following WPF C# code cut down some weight? I mean, WTF, uh... I mean WPF, come one. Have you every seen CSS? I only want to underline the Text when I hover with the mouse just like a link. Do I really have to add 9 lines for that?

<TextBlock x:Name="Cassette_tblPrintLabel" Text="Print Label" Canvas.Left="154" Canvas.Top="215" Foreground="#FF3355FF" Cursor="Hand" MouseDown="Cassette_lblPrintLabel_MouseDown">
    <TextBlock.Style>
        <Style TargetType="TextBlock">
            <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="TextBlock.TextDecoration" Value="Underline" />
            </Trigger>
            </Style.Triggers>
        </Style>
    </TextBlock.Style>
</TextBlock>



在此先感谢!

Thanks in advance!

推荐答案

添加样式的资源;那么至少你可以重新使用它。我认为这是你能做的最好的。

Add the style as resource; then at least you can re-use it. I think that's the best you can do.

<Application.Resources>
    <Style TargetType="TextBlock" x:Key="HoverUnderlineStyle">
        <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="TextBlock.TextDecorations" Value="Underline" />
            </Trigger>
        </Style.Triggers>
    </Style>
</Application.Resources>

<TextBlock Style="{StaticResource HoverUnderlineStyle}" />

这篇关于WPF TextBlock的样式下划线鼠标悬停的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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