Friday, April 29, 2011

How to underline a TextBlock on a MouseEnter

Hello all,

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.

Thanks!

From stackoverflow
  • Use a style:

    <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.)

  • You may find this link helpful: http://msdn.microsoft.com/en-us/library/system.windows.textdecorations.underline.aspx

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.