[英]Xamarin.Forms - KeyNotFoundException: The given key was not present in the dictionary C#
I am using Xamarin.Forms and I getting this error:我正在使用 Xamarin.Forms 并且收到此错误:
KeyNotFoundException: The given key was not present in the dictionary
KeyNotFoundException: 字典中不存在给定的键
For this line:对于这一行:
bool isLogin = (bool)Application.Current.Properties["isLogin"];
I tried to check to see if the key existed like so:我试图检查密钥是否存在,如下所示:
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);
}
}
But checking the key always returns false even after setting the key and value:但是即使在设置了键和值之后,检查键也总是返回 false:
Application.Current.Properties["isLogin"] = true;
Application.Current.Properties will be exists even if you kill the application and restart it again.即使您终止应用程序并重新启动它,Application.Current.Properties 也将存在。 Just try in this way unplug your device and try to login and check, it will work.
只需尝试以这种方式拔下您的设备并尝试登录并检查,它就会工作。 While debugging it won't work.
调试时它不起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.