tags:

views:

1551

answers:

2

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!

+7  A: 

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

itowlson