WPF MVVM中的单选按钮绑定

WPF MVVM中的单选按钮绑定,wpf,mvvm,c#-4.0,Wpf,Mvvm,C# 4.0,有谁能告诉我如何在MVVM中通过单选按钮启用/禁用按钮。通常,它不需要视图模型。您可以使用NotConverter直接绑定两个元素的属性 [ValueConversion(typeof(bool), typeof(bool))] public class NotConverter : IValueConverter { public static readonly IValueConverter Instance = new NotConverter(); public obj

有谁能告诉我如何在MVVM中通过单选按钮启用/禁用按钮。

通常,它不需要视图模型。您可以使用NotConverter直接绑定两个元素的属性

[ValueConversion(typeof(bool), typeof(bool))]
public class NotConverter : IValueConverter
{
    public static readonly IValueConverter Instance = new NotConverter();

    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        bool typedValue = (bool)value;
        return !typedValue;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return Convert(value, targetType, parameter, culture);
    }

}