Reputation: 659
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?
Upvotes: 0
Views: 835
Reputation: 42227
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}" />
Upvotes: 2
Reputation: 4153
This works for me:
<TextBlock Text="MyText" TextDecorations="Underline" />
Upvotes: 0