Windows 8風格應用開發入門 二十六 本地應用資料

來源:互聯網
上載者:User

當應用安裝時,系統會為設定和檔案等應用資料提供它自己的每使用者資料存放區。我們不需要知道這 些資料存在哪裡或如何儲存,因為系統會負責管理實體儲存體工作。我們只需使用應用資料API就可以了 。

本地應用資料一般用於當前裝置資料的持久化,並且本機資料沒有限制大小,通常情況使用 本機資料儲存大型資料集。

如何擷取應用的設定和檔案容器

1.使用 ApplicationData.LocalSettings屬性可以擷取ApplicationDataContainer 對象中的設定。

Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;

2.使用 ApplicationData.LocalFolder 屬性可以擷取StorageFolder 對象中的檔案。

Windows.Storage.ApplicationDataContainer localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;

如何將資料寫入設定

我們可 以通過三種方式將資料寫入設定。

1.使用ApplicationDataContainer.Values屬性。

localSettings.Values["exampleSetting"] = "Hello Windows";

使用鍵-值對的方式。

2.使用ApplicationDataCompositeValue對象,進 行一個複合的設定。

Windows.Storage.ApplicationDataCompositeValue composite = new Windows.Storage.ApplicationDataCompositeValue();          composite["intVal"] = 1;          composite["strVal"] = "string";                         localSettings.Values["exampleCompositeSetting"] = composite;

3.使用 ApplicationDataContainer.CreateContainer方法建立設定容器,將資料添加到容器中。

Windows.Storage.ApplicationDataContainer container =              localSettings.CreateContainer("exampleContainer", Windows.Storage.ApplicationDataCreateDisposition.Always);                         if (localSettings.Containers.ContainsKey("exampleContainer"))          {             localSettings.Containers["exampleContainer"].Values["exampleSetting"] = "Hello Windows";          }

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.