将 IDataErrorInfo 绑定到窗口 IsEnabled 按钮属性

发布于 2024-07-12 01:14:08 字数 306 浏览 8 评论 0原文

我有一个 WPF 子窗口,其中包含一些输入控件,用户必须在按“确定”按钮之前正确填充这些输入控件。

我已经实现了接口 IDataErrorInfo 来验证绑定到 UI 控件的所有属性。

现在我希望仅当所有控件都有效时,“确定”按钮的 IsEnabled 属性才为 True,否则必须将其设置为 False

这应该很容易,但我找不到正确的解决方案。 您有什么建议吗?

提前致谢!

I have a WPF sub window with some input controls that the user has to correctly fill before pressing Ok button.

I have already implemented the interface IDataErrorInfo to validate all properties bound to UI Controls.

Now I would like that the IsEnabled property of Ok button is True only if ALL controls are valid, otherwise it has to be set to False.

It should be easy but I cannot find the correct solution. Do you have any suggestion?

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

懒猫 2024-07-19 01:14:08

Ciao ;-)

我认为您可以通过 IValueConverter 将按钮的 IsEnabled 属性绑定到(例如)数据的 IDataErrorInfo.Error 属性(您必须实现)从string转换为bool(例如,如果String.Empty的值返回true)。

另一种解决方案是使用 Command 并将此逻辑包含在 CanExecute 中:这样,您只需将 Command 与您的 <代码>按钮。
华泰

Ciao ;-)

I think you could bind the IsEnabled property of the button to (e.g.) the IDataErrorInfo.Error property of your data through a IValueConverter (that you have to implement) that converts from string to bool (e.g if the value if String.Empty than return true).

Another solution is to use Commands and have this logic enclosed in the CanExecute: in this way you just have to associate the Command with your Button.
HTH

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文