WPF中的确定性和异步字段验证 [英] deterministic and asynchronous field validation in WPF

查看:100
本文介绍了WPF中的确定性和异步字段验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在基于MVVM的应用程序中,我需要验证数据条目中的字段.如果可能的话,我想将标准WPF验证绑定与ErrorTemplates一起使用.

In my MVVM based application I need to validate fields in a data entry from. If possible, I would like to use the standard WPF validation binding with ErrorTemplates.

不过,出于以下原因,我希望验证逻辑的执行完全由ViewModel驱动(或触发),而不是由View拉动:

However I would like the execution of the validation logic to be completely driven/triggered by the ViewModel (push to the View, not pull by the View) for the following reasons:

  1. 它必须异步运行,因为验证逻辑可能需要一段时间才能执行.
  2. 当执行验证逻辑时(例如,仅在用户单击应用"之后,或者当内部状态以条目突然变为无效的方式更改时),我需要更加确定性和细粒度.

我知道Silverlight具有INotifyDataErrorInfo正是出于这个目的而引入的,但是WPF却没有.仍然如何确定性和异步地执行验证逻辑?

I know Silverlight has INotifyDataErrorInfo which was introduced for exactly this purpose, but WPF doesn't. How can I still have my validation logic exectuted deterministically and asynchronously?

推荐答案

我在您的另一个问题上也给出了答案,显然也回答了这个问题.

I posted an answer on your other question that apparently answered this one too.

从以下位置创建视觉树代码中的控制模板

这篇关于WPF中的确定性和异步字段验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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