0

I made a unit selector radiobutton, "mm" and "inches", to allow the user to switch between metric and imperial units. I have the two radio buttons binding tied to an enum in a settings file. I used this as a reference to do so, and it works great. Storing a radio button selection in the settings.

I now need to refresh all my properties, that have my measurements, to reflect the user preference of metric or imperial. That is on start up say the units are set to metric, but they would like to see what they are in imperial. The user selects the imperial radio button to show the imperial measurements, and all the data will refresh when they click the radio button, "inches", and the display would show in imperial measurements, but how do I get a property changed on a radio button tied to an enum in the settings file? Or if there is a different way?

If I didn't need to store their preference of metric or imperial I would switch to a bool, per radio button, and use notify property changed.

Edit Figured it out. I posted it as the answer.

Community
  • 1
  • 1
Bluto
  • 166
  • 1
  • 15

2 Answers2

0

I see you need to bind to an enum

I think you are still going to need to notify.

You must implement INotifyPropertyChanged

INotifyPropertyChanged

NotifyPropertyChanged();

Will notify all

paparazzo
  • 44,497
  • 23
  • 105
  • 176
  • my enum is in a settings file, if you read the link I added you will see what I did, how can I just add the NotifyPropertyChanged to that? – Bluto Oct 02 '12 at 13:15
  • What I meant in "still need to notify" – paparazzo Oct 02 '12 at 13:46
  • thank you for you help, but your answer was too vague and not very helpful. You can't "still need to notify" with a binding to a User Setting, and if you can that is what I was looking for. I was working on another piece of my code and figured out my mistake. I posted what I found. I think it is along the lines you wanted me to go with the notify of change. – Bluto Oct 02 '12 at 19:43
  • So agree it was vague. Was what I meant but I had to leave before I could expand. – paparazzo Oct 02 '12 at 20:04
0

So I figured it out when I was trying to get a different part of my code working.

My original radiobuttons looked like this.

<!--Unit Selector-->
        <ribbon:RibbonGroup x:Name="Unit_Selection" Header="Units">
            <StackPanel DataContext="{StaticResource Settings}">
                <!--Metric-->
                <RadioButton GroupName="UnitsSelector"  Content="mm" x:Name="Metric" IsChecked="{Binding Path=Default.Units, Mode=TwoWay, Converter={StaticResource enumBooleanConverter},
                     ConverterParameter=mm}" />

                <!--Imperial-->
                <RadioButton GroupName="UnitsSelector" Content="inches"  x:Name="Imperial" IsChecked="{Binding Path=Default.Units, Mode=TwoWay, Converter={StaticResource enumBooleanConverter}, 
                     ConverterParameter=inches}" />
            </StackPanel>
        </ribbon:RibbonGroup>

Which directed the binding to a User Setting enum.

I changed the binding to a property. To get xaml code

<ribbon:RibbonGroup x:Name="Unit_Selection" Header="Units">
            <StackPanel>
                <RadioButton IsChecked="{Binding Path=UnitProperty, Converter={StaticResource enumBooleanConverter}, ConverterParameter=mm}">mm</RadioButton>
                <RadioButton IsChecked="{Binding Path=UnitProperty, Converter={StaticResource enumBooleanConverter}, ConverterParameter=inches}">inches</RadioButton>
            </StackPanel>
        </ribbon:RibbonGroup>

...and Property

public Unit UnitProperty
    {
        get
        {
            return Properties.Settings.Default.Units;
        }
        set
        {
            if (Properties.Settings.Default.Units != value)
            {
                Properties.Settings.Default.Units = value;
                NotifyPropertyChanged("UnitProperty");
                NotifyPropertyChanged(String.Empty);
            }
        }
    }

I had to add NotifyPropertyChange(String.Empty); to get it to update my other properties.

I also found that I need to add INotifyPropertyChanged as a base class to my notification class.

Now I have to go through and add handling for when the user switches between mm and inches.

Bluto
  • 166
  • 1
  • 15