question

Jon-6146 avatar image
0 Votes"
Jon-6146 asked JarvanZhang-MSFT commented

How to update preferences within the same app session

I've created a settings page within xamarin on my code behind that works just fine to update preferences when the app restarts. The purpose of this is to change the language of the app according to the bool value saved by the preference. It works great between app sessions (closing and restarting the app). However, I can't seem to get it to update within the SAME app session. Example, you tap the switch and everything changes to spanish instantly without the app needing to restart.

See attached for code.85902-code.txt


dotnet-xamarin
code.txt (3.3 KiB)
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi, Jon. What platform did you test and face the problem? On Android, the language settings are detected and cached when the application starts. If you change languages, you may need to exit and restart the application to see the changes applied.

Check the doc: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/localization/text?pivots=windows#test-localization

0 Votes 0 ·

I encountered the issue on Android but this has nothing to do with language settings and everything to do with Xamarin Preferences. If you look at the code in the txt file, you'll see that i'm just reading the boolean value set by preferences. This works great between app sessions but my question is how to tell the homeviewmodel to update. I have a web background and I know a lot of times there's something like thispage.onload...is there anything like that in xamarin??

0 Votes 0 ·

If you look at the code in the txt file, you'll see that i'm just reading the boolean value set by preferences.

I tested the code in a basic demo, the preference works fine. How did you change the app's language? Did you set data binding for the controls? To update the UI at runtime, please make sure the properties of the model class raise the PropertyChanged event.

0 Votes 0 ·

0 Answers