c# - 首选项 Xamarin.Essentials - 第一次检查是否为空?
问题描述
我正在使用 Xamarin.Forms 并尝试在启动应用程序后检查首选项是否为空或 null。像这样的东西
InitializeComponent();
if (Preferences.ismpty || Preferences == null)
{
MainPage = new GamerTagPage();
}
else
{
MainPage = new HomePage();
}
解决方案
我在用着:
if (Preferences.ContainsKey("YourKey") || string.IsNullOrEmpty(Preferences.Get("YourKey", string.Empty)))
{
//Your code if exist
}
else
{
//Your code if not exist
}
这应该在大多数情况下起作用。
推荐阅读
- docker - 为什么即使我指定了 --sslcert 和 --sslkey,Portainer 仍会忽略我的证书?
- sql - Oracle SQL,计算未按计划进行
- c# - C# 如何将代码附加到正在运行的 .NET .EXE 的末尾,最好是从该 .EXE 内部?
- flutter - 如何检查一个字母是大写还是小写?- Flutter
- c - 从代码索引 int 数组逆向工程数组维度?
- java - 是否可以将自定义对象传递到 SpringBoot 的端点?
- aws-cdk - AWS CDK 获取 Pinpoint 项目/应用程序 ID
- android - JSON 值不会插入 ArrayList
- php - 如何获取响应对象的“变量”
- python - 推送到远程服务器时出现 Jupyter 实验室错误