Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextBlock Text property can't be set via style trigger if non-empty - why?

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?

like image 326
Sergey Aldoukhov Avatar asked May 01 '09 19:05

Sergey Aldoukhov


1 Answers

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

http://msdn.microsoft.com/en-us/library/ms743230.aspx

like image 167
Spink Avatar answered Sep 28 '22 06:09

Spink