假设我有以下内容:
<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
属性来计算所选的单选按钮。
SelectedItem
绑定到感兴趣的属性。 - H.B.