我知道如何在 windows phone apps 中只显示一次消息框,下面是代码
if (!IsolatedStorageSettings.ApplicationSettings.Contains("IsThirdLaunchDone"))
{
MessageBox.Show("Click on '...', go to settings and select your city and country.");
IsolatedStorageSettings.ApplicationSettings["IsThirdLaunchDone"] = true;
}
但我正在尝试为我的 Windows 8应用移植相同但无法获得它。
if (!ApplicationData.Current.LocalSettings.Containers.ContainsKey("IsThirdLaunchDone"))
{
//MessageDialog Code goes here
ApplicationData.Current.LocalSettings["IsThirdLaunchDone"] = true; //**Error code**
}
错误 - 无法将[]索引应用于' Windows.Storage.ApplicationDataContainer'
类型的表达式需要帮助!
答案 0 :(得分:2)
错误告诉您正在尝试访问不包含值的内容的值。尝试这样的事情:
if (!ApplicationData.Current.LocalSettings.Values.ContainsKey("IsThirdLaunchDone"))
{
//MessageDialog Code goes here
ApplicationData.Current.LocalSettings.Values["IsThirdLaunchDone"] = true;
}
请注意在get和set中始终使用Values
。 (而不是Containers
)