views:

11

answers:

1

I have a couple of TextBlocks, bound to different things. Both TextBlocks have the same style applied. In the style there is an eventtrigger which flashes the text when the bound value updates. All works great however when the value for one textblock updates, both textblocks flash. I was expecting just one TextBlock to flash. Any ideas?

    <Style x:Key="flashingTextBlock" TargetType="TextBlock">
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="Foreground" Value="#333333" />
        <Style.Triggers>
            <EventTrigger RoutedEvent="Binding.TargetUpdated">
                <BeginStoryboard>
                    <Storyboard>
                        <ColorAnimation     
                                Storyboard.TargetProperty="(TextBlock.Foreground).(SolidColorBrush.Color)"
                                To="Orange"              
                                Duration="0:0:1"
                                AutoReverse="True"/>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
        </Style.Triggers>
    </Style>

<TextBlock Text="{Binding Path=PcName, NotifyOnTargetUpdated=True}" 
        Style="{StaticResource flashingTextBlock}"/>
<TextBlock Text="{Binding Path=Time, NotifyOnTargetUpdated=True}" 
        Style="{StaticResource flashingTextBlock}"/>
+1  A: 

Basically I cannot reproduce this (with a similar config).

I suggest you verify what is actually happening. It could be that your codebehind (ViewModel) is calling PropertyChanged to enthusiastically.

Henk Holterman
Yes! you are absolutelly right. I checked the code behind and I am, indeed, updating several values instead of one. Thanks for taking the time to answer.