Alex Rivera | Logout

How to detect a change in the Text property of a TextBlock?

Asked 2009-03-31T21:37:25.883
32

Is there any way to detect a change in the Text property of a TextBlock element using events?

(I'm trying to provide an animation for highlighting the TextBlocks whose Text property change within a DataGrid)

Edit
Report

1 Answer

10

As far as I can understand there isn't any textchanged event in TextBlock. Looking at your requirement, I feel that re-templating a textbox will also not be a viable solution. From my preliminary searching around, this seems to be a possible solution.

<TextBlock x:Name="tbMessage" Text="{Binding Path=StatusBarText, NotifyOnTargetUpdated=True}">
    <TextBlock.Triggers>
        <EventTrigger RoutedEvent="Binding.TargetUpdated">
            <BeginStoryboard>
                <Storyboard>
                    <DoubleAnimation Storyboard.TargetProperty="Opacity" Duration="0:0:0″
To="1.0″ />
                    <DoubleAnimation Storyboard.TargetProperty="Opacity" Duration="0:0:2″
From="1.0″ To="0.0″ BeginTime="0:0:5″ />
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </TextBlock.Triggers>
</TextBlock>
answered 2009-03-31T22:18:06.270

Your Answer