tags:

views:

311

answers:

1

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?

+4  A: 

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

Spink
This is a great link. Explains a _lot_ of what I've thought were my bugs and just took different approaches.
siz
Still they could design it that while style setters are lover than local values, style _triggers_ would be higher... Because both animations and data triggers can easily override the local value, style trigger being dynamic could fall into that category as well.
Sergey Aldoukhov