<RadioButton Content="Yes" IsChecked="{Binding UserChoice}"/>
<RadioButton Content="No"/>
需要用如下的方式:
<RadioButton Content="Yes" IsChecked="{Binding UserChoice}"/>
<RadioButton Content="No" IsChecked="{Binding UserChoice, Converter={StaticResource radioConverter}}"/>
radioconverter如下:
public class RadioButtonConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is bool)
{
return !(bool)value;
}
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is bool)
{
return !(bool)value;
}
return value;
}
}
这样就能正确更新了。