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?

Was it helpful?

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

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top