Reputation: 33
I have this code to go to the next page, sending this parameter:
Frame.Navigate(typeof(MenuPrincipal), 3); // Parameter = 3
This parameter is defined by the user, just to change a image in the next screen, but every time he/she leaves the app and start again, he/she will need to set this parameter again.
Is there any way to save this variable in some file, and when the app start, the file is read by app, and set the variable to 3 automatically.
One time I used XML on a Desktop application to save and read variables, I searched around and didn't find good examples about reading XML file and convert to variables on Windows Phone 8.1. (Don't need to be XML, any way to save and retrieve data is fine).
Upvotes: 0
Views: 889
Reputation: 21889
For small simple data the easiest place is to save it in app settings:
const string MyParameterName = "MyParameter";
// Save
ApplicationData.Current.RoamingSettings.Values[MyParameterName] = 3;
// Restore
int myParameter = (int)ApplicationData.Current.RoamingSettings.Values[MyParameterName];
If you want to save as XML then take a look at the XmlSerializer or DataContractSerializer classes to serialize an object to XML or the XmlDocument class to manage the XML yourself.
You can save it in ApplicationData with the StorageFile and FileIO classes.
See Accessing app data with the Windows Runtime
Upvotes: 3