我正在编写一个 Windows Phone 8 应用程序,因此我可以获得非常抢手的 3% 的市场份额,并且很难在应用程序中保留用户设置。
我第一次遇到 this blog它介绍了 Windows.Storage 命名空间的基础知识,它的目的就是做这种事情。耶!
但是,我猜作者从未真正运行他自己的代码,否则他会知道当您调用 ApplicationData.Current.LocalSettings
时,您会得到NotImplementedException
异常。 To the MSDNs we go!
好吧,这很清楚这个 API 没有在 Windows Phone 8 上实现。当它说“这个 API 没有实现,如果调用会抛出异常”时,我得出了这个结论。 - 那太好了。
所以,也许还有一些其他类似的 API。经过更多的谷歌搜索,我遇到了 this blog .它被称为“Windows 8 应用程序 - 必须知道的技巧!”。这看起来很正式!它涵盖了各种看起来非常酷的持久性 API,包括永久和临时存储、漫游存储等。
但猜猜是什么:RoamingFolder
、RoamingSettings
、TemporaryFolder
、LocalSettings
- 它们都没有在 Windows 上实现电话 8.
实现这些有些关键的功能是否让他们忘记了?我应该创建一个本地 SQL 数据库来存储基本的应用程序设置,还是有一些简单的东西我没有找到?
最佳答案
啊哈!想通了。我查阅了 Windows Phone 7 API 文档,发现遗留 API 实际上仍然适用于 Windows Phone 8。
public static void Session_PersistSession(string ticket)
{
if (IsolatedStorageSettings.ApplicationSettings.Contains("SessionTicket"))
{
IsolatedStorageSettings.ApplicationSettings["SessionTicket"] = ticket;
}
else
{
IsolatedStorageSettings.ApplicationSettings.Add("SessionTicket", ticket);
}
IsolatedStorageSettings.ApplicationSettings.Save();
}
public static string Session_LoadSession()
{
string ticket;
if (IsolatedStorageSettings.ApplicationSettings.TryGetValue<String>("SessionTicket", out ticket))
{
return ticket;
}
return null;
}
关于c# - 普通人应该如何在 Windows Phone 8 应用程序中保留设置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13558809/