开发者

radio button binding in WPF MVVM

开发者 https://www.devze.com 2023-01-03 12:04 出处:网络
can any one tell me how can we enabl开发者_JS百科e/ disable button by radio button in MVVM.Generally, it does not require view model. You can bind properties of two elements directly by using NotConve

can any one tell me how can we enabl开发者_JS百科e/ disable button by radio button in MVVM.


Generally, it does not require view model. You can bind properties of two elements directly by using 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);
    }

}

< RadioButton Name=radio /> < Button IsEnabled={Binding Path=IsChecked, ElementName=radio, Converter={x:Static ns:NotConverter.Instance}} />


The ViewModel sample application of the WPF Application Framework (WAF) shows how to bind ViewModel properties to RadioButtons.

0

精彩评论

暂无评论...
验证码 换一张
取 消