TextBox TextChanged事件与程序化与用户更改文本内容 [英] TextBox TextChanged event on programmatic versus user change of text contents

查看:404
本文介绍了TextBox TextChanged事件与程序化与用户更改文本内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想区分以编程方式更改文本
(例如按钮点击处理程序事件)和用户输入(打字,
切割和粘贴文本)。

可以吗?

I would like to differentiate between changing the text programmatically (for example in a button click handler event) and user input (typing, cutting and pasting text).
Is it possible?

推荐答案

如果您只想使用内置的WPF TextBox,我不相信这是可能的。

If you just want to use the built-in WPF TextBox, then I don't believe it's possible.

在Silverlight论坛上有一个类似的讨论: http://forums.silverlight.net/p/119128/268453.aspx
这不是完全一样的问题,但我认为这个想法类似于原来的帖子可能会为你做的伎俩。在一个子类TextBox上有一个SetText方法,在更改文本之前设置一个标志,然后将其重新设置。然后,您可以检查TextChanged事件中的标志。这当然要求您所有的程式化文字变更都可以使用该方法,但是如果您对该项目有足够的控制权来强制我认为这样做。

There is a similar discussion on the Silverlight forums here: http://forums.silverlight.net/p/119128/268453.aspx It's not exactly the same question, but I think the idea similar to that in the original post might do the trick for you. Have a SetText method on a subclassed TextBox, that set a flag before changing the text and then set it back after. You could then check for the flag inside the TextChanged event. This would of course require all of your programmatic text changes to use that method, but if you have enough control over the project to mandate that I think it would work.

这篇关于TextBox TextChanged事件与程序化与用户更改文本内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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