views:

194

answers:

2

If I want to display an underlined value in a TextBlock, I have to use a Run element. (If there's a better/easier way, I'd love to hear about it.)

<TextBlock>
  <Run TextDecorations="Underline" Text="MyText" />
</TextBlock>

Ideally, to implement this within a DataTemplate, it would look something like this:

<DataTemplate x:Key="underlineTemplate">
  <TextBlock>
    <Run TextDecorations="Underline" Text="{Binding Value}" />
  </TextBlock>
</DataTemplate>

This won't work, however, because the Run's Text property isn't a DependencyProperty, so you can't databind to it. Does anyone know how I can accomplish this?

A: 

This works for me:

<TextBlock Text="MyText" TextDecorations="Underline" />
sacha
+2  A: 

TextDecoration is an attached property so it can be applied to the TextBlock also. You create some pretty cool effects by templating the TextDecorations property.

See this MSDN article.

<TextBlock TextDecorations="Underline" Text="{Binding Value}" />
joshperry