2014-05-07 57 views
0

我已經基於測驗遊戲創建了Windows手機應用程序。我希望當用戶給出一些問題的正確答案時,問題標籤上的小勾號將會永久顯示。 我想存儲每個問題的分數,以便我可以在地名中顯示爲'您的分數'。即使應用已關閉,該分數也不會重置。在windows phone應用程序中存儲和獲取數據

+0

你有沒有做過這方面的任何研究嗎?您可以在Google或甚至StackOverflow上找到大量答案... –

回答

0

你可以使用應用程序IsolatedStorage保存文件。

reference

#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 
+1

您的代碼缺少'mySettings.Save()' - 沒有此數據將不會在應用程序的單獨運行之間保留。我不確定是否在OP的情況下使用IsolatedStorageFile或數據庫不會更好。如果有很多問題,可以將其例如序列化爲字典或列表 - 如果ISS也可以完成,但不應使用IMO ISS來存儲「大量」數據。 – Romasz

+0

謝謝@Romasz。我會盡快更新 – Eldho

相關問題