首页 > 解决方案 > 首选项 Xamarin.Essentials - 第一次检查是否为空?

问题描述

我正在使用 Xamarin.Forms 并尝试在启动应用程序后检查首选项是否为空或 null。像这样的东西

InitializeComponent();
if (Preferences.ismpty || Preferences == null)
{
MainPage = new GamerTagPage();
}
else
{
MainPage = new HomePage();
}   

     
         

标签: c#xamarinxamarin.formsxamarin.essentials

解决方案


我在用着:

 if (Preferences.ContainsKey("YourKey") || string.IsNullOrEmpty(Preferences.Get("YourKey", string.Empty)))
{
   //Your code if exist
}
else
{
   //Your code if not exist
}

这应该在大多数情况下起作用。


推荐阅读