2012-01-05 40 views
0

任何1請提出一個方法,我可以存儲我所有的問題,多項選擇答案和正確的答案。這樣我可以打電話給他們,然後在文本框和單選按鈕中顯示。當用戶正確回答問題時,我應該能夠轉到下一個問題。贏得電話7測驗應用

這是我的方法。使用過的數據序列化,創建了一個包含數據記憶的類,它將存儲問題ID,問題和答案。然後在頁面加載時爲它創建一個對象。但我無法顯示問題。請幫助我。

回答

0

我對你的方法有點困惑。序列化本身並不會實際存留數據。也許這是你的問題。我發現將XML存儲到IsolatedStorage是保存數據的更簡單方法之一。

我創建了一個類似於保存XDocument對象的IsolatedStorage類。

public static void SaveDataToIsolatedStorage(string filePath, FileMode fileMode, XDocument xDoc) 
     { 
      using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication()) 
      { 
       using (IsolatedStorageFileStream location = new IsolatedStorageFileStream(filePath, fileMode, storage)) 
       { 
        System.IO.StreamWriter file = new System.IO.StreamWriter(location); 
        xDoc.Save(file); 
       } 
      } 
     } 

這是我的讀者。

private static XDocument ReadDataFromIsolatedStorageXmlDoc() 
     { 
      using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication()) 
      { 
       if (!storage.FileExists(filePath)) 
       { 
        return new XDocument(); 
       } 

       using (var isoFileStream = new IsolatedStorageFileStream(filePath, FileMode.OpenOrCreate, storage)) 
       { 
        using (XmlReader reader = XmlReader.Create(isoFileStream)) 
        { 
         return XDocument.Load(reader); 
        } 
       } 
      } 
     }