问题描述
我想到的唯一方法是将每个组框的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组单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!