Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF TextBlock text changed notify

I have a screen contain about 15-20 TextBlocks each one bind to a different property, at first all the TextBlocks are empty the text update come from other client.

The thing I want to do is to animate flashing text for 3 seconds when ever text change.

I used the below storyboard to make that happen:

    <Setter Property="Visibility" Value="Visible"/>

       <Style.Triggers>
        <EventTrigger RoutedEvent="UIElement.MouseEnter">  

            <BeginStoryboard >
                <Storyboard Duration="0:0:03">
                    <ObjectAnimationUsingKeyFrames BeginTime="00:00:00"  Storyboard.TargetProperty="(UIElement.Visibility)">
                        <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{x:Static Visibility.Visible}"/>
                        <DiscreteObjectKeyFrame KeyTime="00:00:00.5" Value="{x:Static Visibility.Hidden}"/>
                        <DiscreteObjectKeyFrame KeyTime="00:00:01" Value="{x:Static Visibility.Visible}"/>
                        <DiscreteObjectKeyFrame KeyTime="00:00:01.5" Value="{x:Static Visibility.Hidden}"/>
                        <DiscreteObjectKeyFrame KeyTime="00:00:02" Value="{x:Static Visibility.Visible}"/>
                        <DiscreteObjectKeyFrame KeyTime="00:00:02.5" Value="{x:Static Visibility.Hidden}"/>
                        <DiscreteObjectKeyFrame KeyTime="00:00:03" Value="{x:Static Visibility.Visible}"/>
                    </ObjectAnimationUsingKeyFrames>
               </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </Style.Triggers>
</Style>

Using the mouse enter event the text flash is fine but using the Binding.TargetUpdated event didn't trigger anything.

Anyone know about event that raise when the TextBlock text is changed ?

like image 427
Eran Avatar asked Jun 03 '10 05:06

Eran


2 Answers

did you set the NotifyOnTargetUpdated property to true

<TextBlock Text="{Binding Path=YourProperty, NotifyOnTargetUpdated=True}" TargetUpdated="OnTargetUpdated"/>
like image 142
Amsakanna Avatar answered Nov 10 '22 17:11

Amsakanna


Already a bit old, but here the solution in pure xaml:

<TextBlock VerticalAlignment="Center"
           Text="{Binding ErrorMsg, NotifyOnTargetUpdated=True}">
    <TextBlock.Triggers>
        <EventTrigger RoutedEvent="Binding.TargetUpdated">
            <BeginStoryboard>
                <Storyboard>
                    <DoubleAnimation BeginTime="0:0:0"
                                     Duration="0:0:1"
                                     From="0.0"
                                     Storyboard.TargetProperty="Opacity"
                                     To="1.0" />
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </TextBlock.Triggers>
</TextBlock>
like image 45
Rolfi Avatar answered Nov 10 '22 16:11

Rolfi