如何在Silverlight中监视TextBlock控件的Text属性更改? [英] How to monitor Text property changes of the TextBlock control in silverlight?

查看:73
本文介绍了如何在Silverlight中监视TextBlock控件的Text属性更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

实际上标题包含所有问题.我的页面上有一个TextBlock控件,我想监视它的Text属性以在事件发生更改时触发事件.如果有人可以提出解决方案,请这样做.
提前谢谢!

最好的问候,
Kemo.

尊敬的Parwej Ahamad,
感谢你的快速回复.但是我的要求确实不同.因此,原因是-我想为TextBlock控件实现一个行为,该行为会在文本符号更改时对符号进行动画处理.因此,在这种情况下,每当我需要动画时,我只想将行为添加到TextBlock中,而无需修改后面的代码.而且,无论何时删除该行为,文本都将不再具有动画效果,并且不需要再次修改代码.这是我唯一的原因.

Hello everyone,

Actually the title contains all the question. I have a TextBlock control on my my page, I would like to monitor it''s Text property to fire an event whenever it is changed. If anybody can suggest a solution, please do.
Thank you in advance!

Best Regards,
Kemo.

Dear Parwej Ahamad,
Thank you for your quick response. But my requirements are really different. So the reason is - that I want to implement a behavior for TextBlock control, which animates the text symbol by symbol when it changes. So in this case, whenever I need the animation, I just want to add the behavior to the TextBlock without modifying the code behind. And whenever I remove the behavior, the text will not be animated any more, and I don''t need to modify the code again. This is my only reason.

推荐答案

根据我的理解,为什么不以源代码管理的变更事件为目标?让我解释一下:

TextBlock不是输入控件,因此应该是您将TextBlock控件与TextBox绑定在一起,并由最终用户输入文本,或者您正在从其他来源设置TextBox值.因此,只需捕获TextBox TextChanged事件,并在后面的代码中即可按需执行.

As per my understanding why you don''t target change event of source control? Let me explain:

TextBlock is not an input control so there supposed to be you are binding TextBlock control with TextBox and end user entering the text or you are setting TextBox value from some other source. So Just you can trap the TextBox TextChanged event and in code behind you can perform as your requirement.

Please let me know if your requirement is different.


实际上...我在表达论坛中找到了答案...我会与有兴趣的人分享...建议将Text属性绑定到我自己的DependencyProperty,后者具有事件触发器.那就是我现在要做的.我将选择第一个答案作为解决方案,因为我无法选择自己的答案,但请读者注意...这是主要思想;)
干杯...

最佳Regad,
Kemo.
Actually... I found the answer in the Expression forum... I would share it with those who are interested in... Somebody suggested to bind the Text property to my own DependencyProperty, which has an event trigger. That is what I am going to do now. I am going to Select the 1st answer as the solution, because I cannot choose my own, but note for readers... Here is the main idea ;)
Cheers...

Best Regads,
Kemo.


您完全正确.您必须选择使用与TextBlock绑定的DependencyProperty.请记住,如果要绑定数据,则必须使用DependencyProperty而不是常规的CLR属性.

如果您需要有关DependencyProperty的任何帮助,请访问我的博客文章: http://kunal2383.blogspot .com/2009/05/how-to-implement-dependencyproperty.html [ ^ ]

最好的...:thumbsup:
You are exactly right. You have to chose using the DependencyProperty binded with the TextBlock. Remember that, if you want to bind data you must have to use DependencyProperty instead of normal CLR Property.

If you need any help on DependencyProperty visit my blog post here: http://kunal2383.blogspot.com/2009/05/how-to-implement-dependencyproperty.html[^]

All the best... :thumbsup:


这篇关于如何在Silverlight中监视TextBlock控件的Text属性更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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