本文介绍了数据绑定到validation.haserror的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将 Validation.HasError 绑定到我的视图模型上的布尔属性.我只想知道何时出现验证错误,以便我可以使用中继命令中的 canexecute 方法禁用 VM 上的按钮.但我收到此错误:

I want to bind Validation.HasError to a boolean property on my viewmodel. I only want to know when there is a validation error so that I can disable my buttons on my VM using canexecute methods from my relay commands. I get this error though:

'Validation.HasError' property is read-only and cannot be set from markup. 

我尝试了不同的模式,它们都会导致此错误.我该怎么做呢?应该没那么难.

I have tried different modes and they all cause this error. How do I do this? It shouldnt be this difficult.

推荐答案

您不能在只读依赖项属性上设置绑定.这是 的已知错误微软连接.你可能会投赞成票.

You can't set a Binding on a read-only dependency property. This is a known bug at Microsoft Connect. You might vote for it.

WPF 应用程序框架 (WAF)BookLibrary 示例应用程序> 展示了如何监听 Validation.HasError 属性并禁用一些按钮.

The BookLibrary sample application of the WPF Application Framework (WAF) shows how to listen to the Validation.HasError property and disable some buttons.

这篇关于数据绑定到validation.haserror的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 12:01