我目前无法找到如何在Windows通用项目中实现隔离存储。
我想要做的就是在单击按钮时在隔离存储中保存一些文本,并且稍后可以在其他页面上检索它以供使用。
答案 0 :(得分:2)
您可以使用ApplicationData.Current.LocalSettings
作为字典,您可以在其中保存一些原始对象。
ApplicationData.Current.LocalSettings.Values["MyKey"] = MyValue;
if (ApplicationData.Current.LocalSettings.Values.ContainsKey("MyKey"))
MyValue = ApplicationData.Current.LocalSettings.Values["MyKey"];
答案 1 :(得分:1)
您可以在UWP中本地存储您的应用数据,例如ApplicationData.Current.LocalFolder
,这就是你所谈论的'孤立存储'。以下是您的代码示例:
//Create dataFile.txt in LocalFolder and write “My text” to it
StorageFolder localFolder = ApplicationData.Current.LocalFolder;
StorageFile sampleFile = await localFolder.CreateFileAsync("dataFile.txt");
await FileIO.WriteTextAsync(sampleFile, "My text");
//Read the first line of dataFile.txt in LocalFolder and store it in a String
StorageFile sampleFile = await localFolder.GetFileAsync("dataFile.txt");
String fileContent = await FileIO.ReadTextAsync(sampleFile);
您还可以在此处查看更多详情:Getting started storing app data locally