如何在 Xamarin.Forms 中存储应用程序设置 [英] How to store App settings in Xamarin.Forms

查看:32
本文介绍了如何在 Xamarin.Forms 中存储应用程序设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何在 Xamarin.Forms 中存储和检索应用设置作为键值对?就像应用程序关闭时一样,我们可以存储用户首选项,并在应用程序重新启动时我们能够获取这些值.

How can we store and retrieve App settings as key,value pair in Xamarin.Forms? Like when the app is closed we can store the user preferences and on restarting of the App we are able to get those values.

推荐答案

使用Properties Dictionary

用于存储数据:

Application.Current.Properties ["id"] = someClass.ID;

用于获取数据:

if (Application.Current.Properties.ContainsKey("id"))
{
    var id = Application.Current.Properties ["id"] as int;
    // do something with id
}

ref: https://developer.xamarin.com/guides/xamarin-forms/working-with/application-class/#Properties_Dictionary

这篇关于如何在 Xamarin.Forms 中存储应用程序设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆