Windows phone 8 在windows phone应用程序中存储和获取数据

Windows phone 8 在windows phone应用程序中存储和获取数据,windows-phone-8,windows-phone,windows-applications,Windows Phone 8,Windows Phone,Windows Applications,我已经创建了一个基于问答游戏的Windows phone应用程序。我希望当用户给出某个问题的正确答案时,问题选项卡上会永久出现一个小记号。 我想存储每个问题的分数,以便在地名中显示为“您的分数”。即使应用程序关闭,该分数也不会重置。您可以使用应用程序隔离存储来保存文件 #区域保存并从应用程序存储器加载参数 void saveToAppStorage(字符串参数名称、字符串参数值) { //使用mySettings访问应用程序存储 IsolatedStorageSettings mySettin

我已经创建了一个基于问答游戏的Windows phone应用程序。我希望当用户给出某个问题的正确答案时,问题选项卡上会永久出现一个小记号。
我想存储每个问题的分数,以便在地名中显示为“您的分数”。即使应用程序关闭,该分数也不会重置。

您可以使用应用程序隔离存储来保存文件

#区域保存并从应用程序存储器加载参数
void saveToAppStorage(字符串参数名称、字符串参数值)
{
//使用mySettings访问应用程序存储
IsolatedStorageSettings mySettings=IsolatedStorageSettings.ApplicationSettings;
//检查参数是否已存储
if(mySettings.Contains(ParameterName))
{
//如果参数存在,则写入新值
mySettings[ParameterName]=参数值;
}
其他的
{
//如果参数不存在,请创建它
添加(ParameterName,ParameterValue);
}
}
字符串loadFromAppStorage(字符串参数名称)
{
字符串returnValue=“\u notSet\u”;
//使用mySettings访问应用程序存储
IsolatedStorageSettings mySettings=IsolatedStorageSettings.ApplicationSettings;
//检查参数是否存在
if(mySettings.Contains(ParameterName))
{
//如果参数存在,则写入新值
TryGetValue(ParameterName,out returnValue);
//或者,可以使用以下语句:
//returnValue=(字符串)mySettings[ParameterName];
}
返回值;
}
#端区

您的代码缺少
mySettings.Save()
-如果没有此数据,将无法在单独运行应用程序之间保留数据。我不确定在OP的情况下,使用IsolatedStorageFile或数据库是否会更好。如果有很多问题,例如可以将它们序列化为字典或列表-如果ISS也可以这样做,但是IMO ISS不应该用于存储“大量”数据。你对此做过任何研究吗?你可以在谷歌甚至StackOverflow上找到大量答案。。。
 #region Save and Load Parameters from the Application Storage

    void saveToAppStorage(String ParameterName, String ParameterValue)
    {
        // use mySettings to access the Apps Storage
        IsolatedStorageSettings mySettings = IsolatedStorageSettings.ApplicationSettings;

        // check if the paramter is already stored
        if (mySettings.Contains(ParameterName))
        {
            // if parameter exists write the new value
            mySettings[ParameterName] = ParameterValue;
        }
        else
        {
            // if parameter does not exist create it
            mySettings.Add(ParameterName, ParameterValue);
        }
    }

    String loadFromAppStorage(String ParameterName)
    {
        String returnValue = "_notSet_";
        // use mySettings to access the Apps Storage
        IsolatedStorageSettings mySettings = IsolatedStorageSettings.ApplicationSettings;

        // check if the paramter exists
        if (mySettings.Contains(ParameterName))
        {
            // if parameter exists write the new value
            mySettings.TryGetValue<String>(ParameterName, out returnValue);
            // alternatively the following statement can be used:
            // returnValue = (String)mySettings[ParameterName];
        }

        return returnValue;
    }
    #endregion