WPF TextBlock 文本更改通知 [英] WPF TextBlock text changed notify

查看:31
本文介绍了WPF TextBlock 文本更改通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含大约 15-20 个 TextBlocks 的屏幕,每个 TextBlocks 绑定到不同的属性,起初所有 TextBlocks 都是空的,文本更新来自其他客户端.

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.

我想要做的事情是在文本发生变化时动画闪烁文本 3 秒.

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>

使用鼠标输入事件文本闪烁很好,但使用 Binding.TargetUpdated 事件没有触发任何东西.

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

有谁知道当 TextBlock 文本更改时引发的事件?

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

推荐答案

您是否设置了 NotifyOnTargetUpdated 属性为 true

did you set the NotifyOnTargetUpdated property to true

<TextBlock Text="{Binding Path=YourProperty, NotifyOnTargetUpdated=True}" TargetUpdated="OnTargetUpdated"/>

这篇关于WPF TextBlock 文本更改通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆