TextBlock Text property can't be set via style trigger if non-empty - why?
Question
The XAML below does not work (the text does not change when mousing over):
<Window.Resources>
<Style TargetType="TextBlock">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Text" Value="hover"/>
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid>
<TextBlock Text="original"/>
</Grid>
But, if the Text attribute is missing:
<Grid>
<TextBlock/>
</Grid>
The text does change on mouse over. Anybody knows the theory behind this?
Solution
It's a DependencyProperty precedence issue, when you actually set the property as in:
<TextBlock Text="original"/>
that takes precedence over the value set in the trigger.
see
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow