【发布时间】:2016-01-20 13:51:41
【问题描述】:
我有一个窗口,我想将这个窗口的一部分从没有 RadioButton 的另一部分更改。从这个单选按钮中,我希望客户选择需要在窗口的另一部分看到的部分。类似于 Visual Studio 中的“选项”窗口。
我在一组中只有几个单选按钮,并且希望视图模型知道当用户选择其中一个单选按钮时选择了哪个单选按钮。
我找到了example how I can bind in XAML,但无法理解视图模型如何知道选择了哪个单选按钮。
这是我的简单看法:
<RadioButton GroupName="Settings" IsChecked="{Binding SelectSettingSection}" Content="Language" />
<RadioButton GroupName="Settings" IsChecked="{Binding SelectSettingSection}" Content="Color" />
<RadioButton GroupName="Settings" IsChecked="{Binding SelectSettingSection}" Content="Description" />
<RadioButton GroupName="Settings" IsChecked="{Binding SelectSettingSection}" Content="Theme" />
<RadioButton GroupName="Settings" IsChecked="{Binding SelectSettingSection}" Content="Database" />
这组单选按钮可能只有一个属性,还是视图模型上的每个单选按钮都需要五个属性?
“SelectSectionSetting”就是要知道选择了谁,我知道被检查了但我不知道到底是谁
【问题讨论】:
-
你的codeproject链接是最好的解决方案,花点时间了解一下。
-
包括
SelectSettingSection的属性定义 -
您应该添加一个 ViewModel。 stackoverflow.com/questions/4420911/…
-
为什么需要 RadioButton 来实现这种行为?如果你想要 VS 中的 Options 之类的东西,也许 TreeView 或 ListBox 是更好的选择。
-
这篇文章也可能有用并提供一些想法:blog.jerrynixon.com/2014/12/…