在 IsolatedStorageSettings 中恢复计数
Resume Count in IsolatedStorageSettings
当我按下按钮时完美地计数,但是当您退出应用程序并且 return 计数开始再次计数而不是在 IsolatedStorageSettings 中保存的数字时!!
统计IsolatedStorageSettins中保存的个数时如何做到?
(我用的是Windowsphone8.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();
}
}
根据您的代码 Points
将始终在页面加载时初始化为 0,当您单击计数时它将从 0 开始递增。您需要从 appsettings 加载计数并将其放入 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();
}
}
当我按下按钮时完美地计数,但是当您退出应用程序并且 return 计数开始再次计数而不是在 IsolatedStorageSettings 中保存的数字时!! 统计IsolatedStorageSettins中保存的个数时如何做到? (我用的是Windowsphone8.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();
}
}
根据您的代码 Points
将始终在页面加载时初始化为 0,当您单击计数时它将从 0 开始递增。您需要从 appsettings 加载计数并将其放入 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();
}
}