MVVM 组单选按钮

发布于 2024-08-30 10:30:31 字数 114 浏览 2 评论 0原文

使用 MVVM 将多个 RadioButton 绑定到枚举的最佳方法是什么?

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

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.

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

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

发布评论

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

评论(1

坏尐絯 2024-09-06 10:30:31

您可以在 ListBox 中显示 Enum 值,并提供一个带有 RadioButton 和 Enum 名称的特殊 ItemTemplate。然后,RadioButton 的 IsChecked 属性可以绑定到 ListBoxItem 的 IsSelected 属性。当然,您必须将 ListBox 的 SelectionMode 设置为 Single

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.

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