首页 文章

UWP如何使用独立存储

提问于
浏览
-3

我目前无法找到如何在Windows通用项目中实现隔离存储 .

我想要做的就是在单击按钮时在隔离存储中保存一些文本,并且稍后可以在另一个页面上检索它以供使用 .

2 回答

  • 2

    您可以使用 ApplicationData.Current.LocalSettings 作为字典,您可以在其中保存一些原始对象 .

    ApplicationData.Current.LocalSettings.Values["MyKey"] = MyValue;
    
    if (ApplicationData.Current.LocalSettings.Values.ContainsKey("MyKey"))
        MyValue = ApplicationData.Current.LocalSettings.Values["MyKey"];
    
  • 1

    您可以在UWP中本地存储您的应用数据,例如 ApplicationData.Current.LocalFolder ,这是'Isolated storage'你在说什么 . 这是一个代码示例:

    //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

相关问题