在 TextBox 中输入文本时立即触发 TextChanged 事件
在具有 TextChanged
事件的 wpf TextBox
上,它似乎仅在焦点从文本框移开时才会触发;但不是在输入单个字符时。
是否有类似于 TextChanged
的事件,当在文本框中输入字符时立即触发,而不是在焦点更改时触发?
On a wpf TextBox
that has an TextChanged
event, it seems to only fires when focus is taken away from the textbox; but not as individual characters are typed in.
Is there an event similar to TextChanged
that fires immediately when a character is typed into the textbox, rather than when focus changes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以绑定
Text
属性并使用 UpdateSourceTrigger。通过将其设置为
PropertyChanged
,每次文本更改时您都会收到通知。You can bind the
Text
property and make use of the UpdateSourceTrigger.By setting it to
PropertyChanged
, you will get a notification each and every time the text changes.TextChanged
确实在文本更改后立即触发。(如果您对
Text
的绑定不相同,则它完全独立于事件。)TextChanged
does fire as soon as the text is changed.(If you have a binding on
Text
that is not the same thing, it is completely independent from the event.)@Anron 答案是正确的,但我认为它仅在我们进行数据绑定(使用 MVVM)时才有效。
从 @thecorp 问题我了解到的是他正在尝试在文件后面的代码中实现它。
您可以利用文本框的“KeyDown”和“KeyUp”事件,或者如果您使用数据绑定,Aaron anwer 应该可以解决您的问题。
@Anron answer is correct but i think it works only when we are doing Data binding (using MVVM).
From @thecorp question what i have understood is he is trying to it in code behind file.
You can take advantage of "KeyDown" and "KeyUp" events of textbox or if you are using data binding Aaron anwer should resolve your issue.