当我按下按钮完全计算数字时,但当你退出应用程序并返回计数时会再次开始计数,而不是在IsolatedStorageSettings中保存的数字!! 如何计算IsolatedStorageSettins中保存的数字? (我使用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();
}
}
答案 0 :(得分:0)
根据您的代码Points
将始终在页面加载时初始化为0,当您点击计数时,它将从0开始递增。您需要从appsettings加载计数并将其放入Points
< / p>
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();
}
}