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
2010-06-16 13:40:43
i m looking to bind it to a boolean property , in a way it controls enablity of a Button
atul gupta
2010-06-17 08:36:22
So you have a boolean property on your ViewModel? And you want to enable a button when it it true (or false?)?
HullCitySteve
2010-06-17 09:10:58
yes exactly.....
atul gupta
2010-06-21 05:42:51
A:
The ViewModel sample application of the WPF Application Framework (WAF) shows how to bind ViewModel properties to RadioButtons.
jbe
2010-06-18 16:13:47