我有一个Windows Phone 8应用程序,我想升级到WP8.1通用应用程序。 8.1中不支持隔离存储,如何在这种情况下升级隔离设置?
答案 0 :(得分:1)
ApplicationData.LocalSettings - 获取本地应用数据存储中的应用程序设置容器。
NameSpace:Windows.Storage
var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
// Create a simple setting
localSettings.Values["exampleSetting"] = "Hello Windows";
// Read data from a simple setting
Object value = localSettings.Values["exampleSetting"];
if (value == null)
{
// No data
}
else
{
// Access data in value
}
// Delete a simple setting
localSettings.Values.Remove("exampleSetting");
您可以阅读文档here
答案 1 :(得分:0)
包含IsolatedStorageSettings的__ApplicationSettings文件将在通过商店更新时位于应用程序的本地文件夹中。
通过Visual Studio更新应用程序时不是这种情况,因为使用WinRT应用程序替换Silverlight应用程序似乎很困难。
您需要将此文件反序列化为任何已知对象,并将对象存储在其他位置。 以下代码将在WinRT应用程序中获取IsolatedStorageSettings:
public static async Task<IEnumerable<KeyValuePair<string, object>>> GetIsolatedStorageValuesAsync()
{
try
{
using (var fileStream = await ApplicationData.Current.LocalFolder.OpenStreamForReadAsync("__ApplicationSettings"))
{
using (var streamReader = new StreamReader(fileStream))
{
var line = streamReader.ReadLine() ?? string.Empty;
var knownTypes = line.Split('\0')
.Where(x => !string.IsNullOrEmpty(x))
.Select(Type.GetType)
.ToArray();
fileStream.Position = line.Length + Environment.NewLine.Length;
var serializer = new DataContractSerializer(typeof (Dictionary<string, object>), knownTypes);
return (Dictionary<string, object>) serializer.ReadObject(fileStream);
}
}
}
catch (FileNotFoundException)
{
// ignore the FileNotFoundException, unfortunately there is no File.Exists to prevent this
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
return new Dictionary<string, object>();
}