2016-12-17 62 views
0

我通過Visual Studio Remote Machine和Release選擇了在Windows 10 IoT操作系統上運行Raspperry Pi 3上的uwp應用程序。 問題是如何保存我所做的設置,並在稍後運行相同的UWP應用程序時使用相同的設置。如何使用UWP C#存儲設置?

它是如何完成的?我可以從 的文本文件讀取設置Windows.ApplicationModel.Package.Current.InstalledLocation; 但我當然不能保存對同一文本文件的任何更改。 如果我不想將更改保存到文本文件,我應該在哪裏放置文本文件?

但也許我可以用這

Windows.Storage.ApplicationData.Current.LocalSettings; 

但是我怎麼檢查是否有存儲,改爲一個默認值沒有價值?

與此我想保存這些設置它不起作用。 與此相關的一點是,當我再次運行相同的uwp應用程序時,我可以使用這些相同的設置。

var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings; 
localSettings.Values["setting1"] = textBlockDelayValue.Text; 
localSettings.Values["setting2"] = checkShow; 
+2

SO文檔主題:http://stackoverflow.com/documentation/uwp/5944/settings-and-app-data#t=201612170957559009768 – Bart

回答

0

確切位置在哪裏我應該把文本文件,如果我wan't將更改保存到 文本文件?

你可以把在溶液中Windows.Storage.ApplicationData.Current.LocalFolder文本文件,並與這段代碼訪問它:

Windows.Storage.StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder; 
    async void WriteFile() 
    { 
     StorageFile sampleFile = await localFolder.CreateFileAsync("test.txt", 
      CreationCollisionOption.ReplaceExisting); 
     await FileIO.WriteTextAsync(sampleFile, "111"); 
    } 

    async void ReadFile() 
    { 
     try 
     { 
      StorageFile sampleFile = await localFolder.GetFileAsync("test.txt"); 
      String content = await FileIO.ReadTextAsync(sampleFile); 
     } 
     catch (Exception) 
     { 
      // Timestamp not found 
     } 
    } 

但是我怎麼檢查,如果沒有存儲的值,並把代替 默認值?

你可以讀出來是這樣的:

 var value1 = ApplicationData.Current.LocalSettings.Values["setting1"]; 
     var value2 = ApplicationData.Current.LocalSettings.Values["setting2"];