【发布时间】:2012-03-02 01:01:00
【问题描述】:
假设我有:
<RadioButton GroupName="Group1" IsChecked="{Binding Path=RadioButton1IsChecked}" />
<RadioButton GroupName="Group1" IsChecked="{Binding Path=RadioButton2IsChecked}" />
然后在我的数据源类中我有:
public bool RadioButton1IsChecked { get; set; }
public bool RadioButton2IsChecked { get; set; }
public enum RadioButtons { RadioButton1, RadioButton2, None }
public RadioButtons SelectedRadioButton
{
get
{
if (this.RadioButtonIsChecked)
return RadioButtons.RadioButton1;
else if (this.RadioButtonIsChecked)
return RadioButtons.RadioButton2;
else
return RadioButtons.None;
}
}
我可以以某种方式将我的单选按钮直接绑定到SelectedRadioButton 属性吗?我真的只需要 RadioButton1IsChecked 和 RadioButton2IsChecked 属性来计算选定的单选按钮。
【问题讨论】:
-
这个blog post 可能会有所帮助
-
见my answer on a related question,它应该有帮助。
SelectedItem绑定到感兴趣的属性。
标签: wpf binding radio-button radio-group