开发者

radio button binding in WPF MVVM

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜