# WPF Can't get RadioButton to bind



## FordGT90Concept (Aug 6, 2013)

Enumerator:

```
public enum DefaultableBoolean : sbyte
    {
        Default = -1,
        False = 0,
        True = 1
    }
```

Converter:

```
public class EnumToInt32Converter : IValueConverter
    {
        public object Convert(object value, Type targettype, object parameter, CultureInfo culture)
        {
            return System.Convert.ChangeType(value, targettype);
        }
        public object ConvertBack(object value, Type targettype, object parameter, CultureInfo culture)
        {
            return Enum.ToObject(targettype, System.Convert.ToInt32(value));
        }
    }
```

Bound Property:

```
public DefaultableBoolean ReportResultsImmediately
        {
            get { return _ClientConfig.ReportResultsImmediately; }
            set { _ClientConfig.ReportResultsImmediately = value; }
        }
```
Underlying Property:

```
private DefaultableBoolean _ReportResultsImmediately = DefaultableBoolean.Default;
        public DefaultableBoolean ReportResultsImmediately
        {
            get { return _ReportResultsImmediately; }
            set { _ReportResultsImmediately = value; }
        }
```

WPF Resource:

```
<Window.Resources>
        <local:EnumToBooleanConverter x:Key="EnumToBool" />
    </Window.Resources>
```

WPF:

```
<GroupBox Header="Report Results Immediately" ToolTip="Submits completed tasks when they are finished instead of waiting for the next server communication.">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <RadioButton VerticalAlignment="Center" IsChecked="{Binding Path=ReportResultsImmediately, Mode=TwoWay, Converter={StaticResource EnumToBool}, ConverterParameter={x:Static local:DefaultableBoolean.Default}}" Content="Default" />
                <RadioButton VerticalAlignment="Center" IsChecked="{Binding Path=ReportResultsImmediately, Mode=TwoWay, Converter={StaticResource EnumToBool}, ConverterParameter={x:Static local:DefaultableBoolean.True}}" Content="True" Grid.Column="1" />
                <RadioButton VerticalAlignment="Center" IsChecked="{Binding Path=ReportResultsImmediately, Mode=TwoWay, Converter={StaticResource EnumToBool}, ConverterParameter={x:Static local:DefaultableBoolean.False}}" Content="False" Grid.Column="2" />
            </Grid>
        </GroupBox>
```

Everything looks right, it compiles, but when I start the application, it doesn't check the default value nor does it change the underlying variable.  When I put debugging symbols all over it (including in the properties, Convert, and ConvertBack), none of it is ever raised no matter how many times I click on the radios.  Any ideas how to get the radios to update the underlying ReportResultsImmediately variable?


----------



## FordGT90Concept (Aug 7, 2013)

Long story short, I tried everything I could find online and none of it bound.  In the end I used this code to get around the problem:
http://www.codeproject.com/Articles/61725/WPF-radio-buttons-and-enumeration-values

FYI, this is Visual Studio 2012 using .NET Framework 4.0.


----------

