简体   繁体   English

在IsolatedStorageSettings中恢复计数

[英]Resume Count in IsolatedStorageSettings

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!! 当我按下按钮完全计算数字,但当你退出应用程序并返回计数再次开始计数而不是在IsolatedStorageSettings中保存的数字! How can I make it when the counting of the number that was saved in IsolatedStorageSettins? 如何计算IsolatedStorageSettins中保存的数字? (I use Windows phone 8.1 silverlight) (我使用的是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 根据您的代码,当页面加载时, 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();            
    }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM