I'm trying to bind a custom class to a group of 3 Radiobuttons in my WPF app. There should be three possibilities of the class being returned, depending on which button of the group is selected. So i.e.
public class RadioButtonResult
{
public bool Istrue {get; set;}
public string WhichOne {get; set;}
}
should be bound to the 3 radiobuttons in the sense that Button 1 returns
new RadioButtonResult { Istrue = false, WhichOne = "First"}
second one returns an Instance with Istrue = true, etc... I need this because there are 3 possible situations and the element has to bind to both a boolean property and a string property.
I tried using a converter
public class RadioButtonConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
switch (parameter)
{
case "First":
return new RadioButtonResult(false, "First");
case "Second":
return new RadioButtonResult(true, "Second");
case "Third":
return new RadioButtonResult(true, "First");
default:
return new RadioButtonResult(false, "None")
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{ return null; }
}
The radiobuttons themselves should have no text, so I'm not quite sure how to pass the converter parameter to even try this. (I didn't try the ConvertBack yet as I couldn't get the Convert to work)
<RadioButton GroupName="Group1" IsChecked="{Binding TestStatus, Converter=RadioButtonConverter, ConverterParameter="First"}"/>
I tried something like this, but it won't accept text as the parameter. How could I make this converter work?