WPF MVVM-访问视图模型中视图控件的属性 [英] WPF MVVM-Accessing the properties of a control of View in the View Model

查看:63
本文介绍了WPF MVVM-访问视图模型中视图控件的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在视图中使用了不同的切换按钮和按钮.我需要使用视图模型中的 toggleButtons 的 IsEnabled 和 IsChecked 属性来根据某些条件禁用某些按钮和切换按钮.向我建议任何方法来访问视图中控件的任何属性到视图模型.

I am using different toggle buttons and buttons in the view. I need to use the IsEnabled and IsChecked property of the toggleButtons in the view Model to diable some buttons and toggle buttons based on some conditions. Suggest me any methods to access any properties of a control in the view to the view model.

推荐答案

将它们绑定到 View Model 中公开的属性,这样您就不会打破 View 和 View Model 之间的分离.

Bind them to exposed properties in the View Model so you don't break the separation between View and View Model.

在这种情况下,您可以将IsEnabled"绑定到SomethingIsEnabled",然后在设置后,根据属性当前值重新评估您的命令状态.

In this case, you can bind the "IsEnabled" to a "SomethingIsEnabled" and then when that is set, re-evaluate your command status based on the properties current value.

我注意到对于视图模型中的状态,我最终创建了很多这样的东西来保持视图模型中的逻辑",而不是读取视图.

I have noticed that for state within the View Model, I end up creating a lot of things like this to keep the "logic" in the View Model, instead of reading the View.

这篇关于WPF MVVM-访问视图模型中视图控件的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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