如何检测 TextBlock 的 Text 属性的变化? [英] How to detect a change in the Text property of a TextBlock?

查看:40
本文介绍了如何检测 TextBlock 的 Text 属性的变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法使用事件检测 TextBlock 元素的 Text 属性的变化?

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

(我试图提供一个动画来突出显示在 DataGrid 中 Text 属性发生变化的 TextBlock)

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

推荐答案

据我所知,TextBlock 中没有任何 textchanged 事件.看看您的要求,我觉得重新模板化文本框也不是一个可行的解决方案.根据我的初步搜索,this 似乎是一个可能的解决方案.

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>

这篇关于如何检测 TextBlock 的 Text 属性的变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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