WPF TextBlock Style Underline on Mouse Hover

前端 未结 1 2198
离开以前
离开以前 2021-02-20 04:40

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 h

相关标签:
1条回答
  • 2021-02-20 05:23

    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}" />
    
    0 讨论(0)
提交回复
热议问题