MVVM组单选按钮 [英] MVVM Group Radio Button

查看:120
本文介绍了MVVM组单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想到的唯一方法是将每个组框的IsChecked绑定到一个属性,并在该属性的setter中为视图模型中的枚举分配一个值。



任何帮助都不胜感激。

解决方案

您可以在列表框中显示枚举值,并提供一个特殊的 ItemTemplate 与RadioButton加上枚举。 RadioButton的 IsChecked 属性可以绑定到ListBoxItem的 IsSelected 属性。当然,您必须将ListBox的 SelectionMode 设置为 Single


What is the best way of binding a number of RadioButtons to an enum using MVVM?

The only way I can think of is binding each group box's IsChecked to a property, and in the setter of that property assign a value to an enum in the view model.

Any help is appreciated.

解决方案

You could display the Enum values in a ListBox and provide a special ItemTemplate with a RadioButton plus the name of the Enum. The RadioButton's IsChecked property could then be bound to the ListBoxItem's IsSelected property. Of course, you would have to set the ListBox's SelectionMode to Single.

这篇关于MVVM组单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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