I have a scenario where I have kept three different properties for a group of radio buttons Is it possible to make it single?
<RadioButton GroupName="os" IsChecked="{Binding Age} IsChecked="{Binding Name,Mode=TwoWay,Converter={StaticResource enumConverter},ConverterParameter=a}"/>
<RadioButton GroupName="os" IsChecked="{Binding Age,Mode=TwoWay,Converter={StaticResource enumConverter},ConverterParameter=b}"/>
<RadioButton GroupName="os" IsChecked="{Binding Age,Mode=TwoWay,Converter={StaticResource enumConverter},ConverterParameter=c}"/>
Here I Need to write a StringConverter, where I will passing the converter parameter as A,B,C for respective radiobuttons.
public class EnumMatchToBooleanConverter : IValueConverter
{
public object Convert(object value, Type targetType,
object parameter, CultureInfo culture)
{
if (value == null || parameter == null)
return false;
//string checkValue = value.ToString();
//string targetValue = parameter.ToString();
//return checkValue.Equals(targetValue,
// StringComparison.InvariantCultureIgnoreCase);
if (value.ToString() == "True" && (parameter.ToString() == "a" || parameter.ToString() == "b" || parameter.ToString() == "c"))
{
return true;
}
else
return false;
}
public object ConvertBack(object value, Type targetType,
object parameter, CultureInfo culture)
{
if (value == null || parameter == null)
return null;
//bool useValue = (bool)value;
//string targetValue = parameter.ToString();
//if (useValue)
// return Enum.Parse(targetType, targetValue);
//return null;
if (value.ToString() == "True" && (parameter.ToString() == "b" || parameter.ToString() == "a" || parameter.ToString() == "c"))
{
return true;
}
else
return false;
}
}