How to store App settings in Xamarin.Forms

后端 未结 4 2077
攒了一身酷
攒了一身酷 2020-12-05 09:59

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

4条回答
  •  醉话见心
    2020-12-05 10:21

    It can be done this way too using Properties Dictionary

    for storing data:

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

    for fetching data:

    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

提交回复
热议问题