小编oxf*_*xfn的帖子

将radiobuttons绑定到WPF中的属性

让我们想象我有:

<RadioButton GroupName="Group1" IsChecked="{Binding Path=RadioButton1IsChecked}" />
<RadioButton GroupName="Group1" IsChecked="{Binding Path=RadioButton2IsChecked}" />
Run Code Online (Sandbox Code Playgroud)

然后在我的数据源类中,我有:

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;
     }
}
Run Code Online (Sandbox Code Playgroud)

我可以以某种方式将我的单选按钮直接绑定到SelectedRadioButton属性吗?我真的只需要RadioButton1IsCheckedRadioButton2IsChecked属性来计算选定的单选按钮.

wpf binding radio-group radio-button

22
推荐指数
3
解决办法
4万
查看次数

标签 统计

binding ×1

radio-button ×1

radio-group ×1

wpf ×1