tags:

views:

85

answers:

2

can any one tell me how can we enable/ disable button by radio button in MVVM.

A: 

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}} />

STO
i m looking to bind it to a boolean property , in a way it controls enablity of a Button
atul gupta
So you have a boolean property on your ViewModel? And you want to enable a button when it it true (or false?)?
HullCitySteve
yes exactly.....
atul gupta
A: 

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

jbe