取消一个WPF文本框更改事件 [英] Cancelling a WPF TextBox Changed Event

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

问题描述

我在学习WPF的WinForms从未来发展的过程。

I'm in the process of learning WPF coming from WinForms development.

我有一个TextChanged事件分配给我的文本框的一个在我的WPF应用程序。如果用户输入无效数据,我希望能够恢复到previous文本值。

I have a TextChanged event assigned to one of my TextBox's in my WPF application. If the user enters invalid data, I want to be able to revert to the previous text value.

在旧形式的日子,我将与取代的OldValue的NewValue,但似乎WPF不相同的方式工作。

In the old forms day, I would replace NewValue with OldValue, but it seems WPF doesn't work the same way.

这是我能做到这一点实现这一目标的任何想法?我只是不与WPF的思维了吗?

Any ideas on what I could do it achieve this? Am I just not thinking with WPF yet?

感谢。

推荐答案

您可以做两种方式:

  1. previewTextInput 事件,并设置 e.Handled = TRUE 停止TextChanged事件。

  1. Listen to the PreviewTextInput event and set e.Handled = true to stop the TextChanged event.

使用WPF验证。有一个伟大的职位由保罗Stovell在$ C $的CProject 并href="http://www.paulstovell.com/blog/validation-scopes-draft" rel="nofollow">最近的文章在他的博客的一个

Use WPF validation. There is a great post by Paul Stovell on Codeproject and a recent post on his blog.

这些文章将让你开始。这引起了套牢,当我第一次做验证一件事是,检验规则只在运行时绑定更新源。

Those articles will get you started. one thing that got stuck with when I first did validation is that the validation rule only runs when the binding updates the source.

这篇关于取消一个WPF文本框更改事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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