When I press the button count the number perfectly, but when you exit the application and return to count starts counting again and not when the number that was saved in IsolatedStorageSettings!! How can I make it when the counting of the number that was saved in IsolatedStorageSettins? (I use Windows phone 8.1 silverlight)
IsolatedStorageSettings setting = IsolatedStorageSettings.ApplicationSettings;
int Points;
// Constructor
public MainPage()
{
InitializeComponent();
this.Loaded += Page2_Loaded;
}
private void Page2_Loaded(object sender, RoutedEventArgs e)
{
if (setting.Contains("save"))
{
PointsText.Text = setting["save"].ToString();
}
}
private void Counts_Click(object sender, RoutedEventArgs e)
{
Points = Points + 1;
setting["save"] = Points;
PointsText.Text = setting["save"].ToString();
}
}
According to your code Points
will always initialize to 0 when the page loads and when you click count it will increment from 0. You need to load the count from appsettings and put it into Points
private void Page2_Loaded(object sender, RoutedEventArgs e)
{
if (setting.Contains("save"))
{
//Initialize Points with the value from settings
Points = int.Parse(setting["save"].ToString());
PointsText.Text = Points.ToString();
}
}