Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to underline a TextBlock on a MouseEnter

Tags:

c#

wpf

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!

like image 865
Martin Avatar asked Apr 16 '09 01:04

Martin


1 Answers

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

like image 120
itowlson Avatar answered Sep 21 '22 12:09

itowlson