[英]C#: KeyNotFoundException: The given key was not present in the dictionary
[英]Xamarin.Forms - KeyNotFoundException: The given key was not present in the dictionary C#
我正在使用 Xamarin.Forms 并且收到此错误:
KeyNotFoundException: 字典中不存在给定的键
对于这一行:
bool isLogin = (bool)Application.Current.Properties["isLogin"];
我试图检查密钥是否存在,如下所示:
if(Application.Current.Properties.ContainsKey("isLogin"))
{
bool isLogin = (bool)Application.Current.Properties["isLogin"];
string username = Application.Current.Properties["username"].ToString();
if (isLogin)
{
Application.Current.MainPage.Navigation.PushAsync(new MenuPage(), true);
}
}
但是即使在设置了键和值之后,检查键也总是返回 false:
Application.Current.Properties["isLogin"] = true;
即使您终止应用程序并重新启动它,Application.Current.Properties 也将存在。 只需尝试以这种方式拔下您的设备并尝试登录并检查,它就会工作。 调试时它不起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.