<Window x:Class="RadioButtonBindingExample.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <StackPanel>
        <StackPanel.DataContext>
            <local:ViewModel />
        </StackPanel.DataContext>
        <RadioButton Content="Option 1" GroupName="Options" IsChecked="{Binding Option1Selected}" />
        <RadioButton Content="Option 2" GroupName="Options" IsChecked="{Binding Option2Selected}" />
        <RadioButton Content="Option 3" GroupName="Options" IsChecked="{Binding Option3Selected}" />
    </StackPanel>
</Window>

其中 ViewModel 类如下所示:

using System.ComponentModel;
namespace RadioButtonBindingExample
    public class ViewModel : INotifyPropertyChanged
        private bool _option1Selected;
        private bool _option2Selected;
        private bool _option3Selected;
        public bool Option1Selected
            get { return _option1Selected; }
                _option1Selected = value;
                OnPropertyChanged("Option1Selected");
        public bool Option2Selected
            get { return _option2Selected; }
                _option2Selected = value;
                OnPropertyChanged("Option2Selected");
        public bool Option3Selected
            get { return _option3Selected; }
                _option3Selected = value;
                OnPropertyChanged("Option3Selected");
        public event PropertyChangedEventHandler PropertyChanged;
        protected virtual void OnPropertyChanged(string propertyName)
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  •