I have a problem with saving my app settings? I creating windows 10 universal app and I have Slider which value I want to save.
i use this code to save it:
private void musicVolume_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
{
ApplicationDataContainer AppSettings = ApplicationData.Current.LocalSettings;
AppSettings.Values["musicV"] = musicVolume.Value;
}
And in constuctor of page I have this lines of code:
ApplicationDataContainer AppSettings = ApplicationData.Current.LocalSettings;
if (AppSettings.Values.ContainsKey("musicV"))
{
musicVolume.Value = Convert.ToDouble(AppSettings.Values["musicV"]);
}
It supposed to show new value when I go to that page, but it doesn't, it alway show last default one. Why it not working and how to make it work?
PS: sorry for my bad english...
Rather than in the constructor, do the musicVolume.Value
initialization after the Page is loaded by subscribing to the Page Loaded event in the constructor. The Loaded event is the appropriate place to do such initialization.
For example, in the constructor add:
Loaded += Page_Loaded;
And your Loaded event handler as:
private void Page_Loaded(object sender, RoutedEventArgs e)
{
ApplicationDataContainer AppSettings = ApplicationData.Current.LocalSettings;
if (AppSettings.Values.ContainsKey("musicV"))
{
musicVolume.Value = (double)AppSettings.Values["musicV"];
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With