How can I emphasize the value of the data binding from the DataTemplate?

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

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

      

Ideally, to implement this in 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 because the Run Text property is not a DependencyProperty, so you cannot bind to it. Does anyone know how I can do this?

0


source to share


2 answers


TextDecoration is an attached property, so it can be applied to TextBlock as well. You create some pretty cool effects by creating the TextDecorations templated property.

See MSDN article .



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

      

+2


source


This works for me:



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

      

0


source







All Articles