取消一个WPF文本框更改事件文本框、事件、WPF

由网友(一岁就很帅)分享简介:我在学习WPF的WinForms从未来发展的过程。I'm in the process of learning WPF coming from WinForms development.我有一个TextChanged事件分配给我的文本框的一个在我的WPF应用程序。如果用户输入无效数据,我希望能够恢复到previou...

我在学习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?

感谢。

推荐答案

您可以做两种方式:

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

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">最近的文章在他的博客的一个

阅读全文

相关推荐

最新文章