1. Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

WPF Can't get RadioButton to bind

Discussion in 'Programming & Webmastering' started by FordGT90Concept, Aug 6, 2013.

  1. FordGT90Concept

    FordGT90Concept "I go fast!1!11!1!"

    Joined:
    Oct 13, 2008
    Messages:
    13,471 (6.27/day)
    Thanks Received:
    3,428
    Location:
    IA, USA
    Enumerator:
    Code:
        public enum DefaultableBoolean : sbyte
        {
            Default = -1,
            False = 0,
            True = 1
        }
    Converter:
    Code:
        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:
    Code:
            public DefaultableBoolean ReportResultsImmediately
            {
                get { return _ClientConfig.ReportResultsImmediately; }
                set { _ClientConfig.ReportResultsImmediately = value; }
            }
    Underlying Property:
    Code:
            private DefaultableBoolean _ReportResultsImmediately = DefaultableBoolean.Default;
            public DefaultableBoolean ReportResultsImmediately
            {
                get { return _ReportResultsImmediately; }
                set { _ReportResultsImmediately = value; }
            }
    WPF Resource:
    Code:
        <Window.Resources>
            <local:EnumToBooleanConverter x:Key="EnumToBool" />
        </Window.Resources>
    WPF:
    Code:
            <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?
    Crunching for Team TPU
  2. FordGT90Concept

    FordGT90Concept "I go fast!1!11!1!"

    Joined:
    Oct 13, 2008
    Messages:
    13,471 (6.27/day)
    Thanks Received:
    3,428
    Location:
    IA, USA
    Crunching for Team TPU

Currently Active Users Viewing This Thread: 1 (0 members and 1 guest)

Share This Page