Save the value of UseImperialMeasurements as the application parameter (or anywhere you want, actually, but the use case supports customizing the application). You get to this by double-clicking the Properties item in the Project tree in Visual Studio. There just go to the Settings tab and add " UseImperialMeasurements " as a bool , the User area and set the default value.
Then, wherever you are in your code, access and change the value using the Properties.Settings.Default.UseImperialMeasurements property.
If you forget to call Properties.Settings.Default.Save () before closing the form or application, the setting will be "Stick".
In XAML, you will access the settings using this binding:
{Binding Source={x:Static my:Settings.Default},Path=UseImperialMeasurements}
Or, forget the Converters. Highlight this functionality in the ViewModel and save the UseImperialMeasurements value as the application parameter (or anywhere you want, really, but the use case supports customization)
public class BackingDataClass { public double LengthAlwaysMetric { get; set; } } public class BackingDataClassViewModel : INotifyPropertyChanged { public BackingDataClass Data { get; set; } public double Length { get { if (Properties.Settings.Default.UseImperialMeasurements == true) { return ConvertToImperial(Data.LengthAlwaysMetric); } else { return _lengthAlwaysMetric; } } set { if (Properties.Settings.Default.UseImperialMeasurements == true) { Data.LengthAlwaysMetric = ConvertToMetric(value); } else { Data.LengthAlwaysMetric = value; } PropertyChanged(this, new PropertyChangedEventArgs("Length")); } } public event PropertyChangedEventHandler PropertyChanged; }
source share