The best way to save Configuration data in Xamarin.Forms based app?

雨燕双飞 提交于 2019-12-12 23:10:54

问题


I am now working on an Xamarin.Forms based app, and have few questions about this. Is there a best way for me to just save some configuration data? As I am using an MVVM based app in like this

private bool _isActive;
public bool IsActive
{
   get { return _isActive; }
   set
   {
      _isActive = value;
      RaisePropertyChanged(nameof(IsActive))
   }
}

I wanted to save the "IsActive" value when use it other time I load my app.
So is there a best way for me to do this?


回答1:


I would currently advise against using the Application.Properties feature of Xamarin Forms, as it is not particularly reliable nor resilient. Instead, I would recommend using the cross-platform settings plugin (On NuGet: https://www.nuget.org/packages/Xam.Plugins.Settings/ and source code / docs: https://github.com/jamesmontemagno/Xamarin.Plugins/tree/master/Settings), which provides just as simple of an API but without the problems of the Application.Properties feature.

The settings plugin also has some additional benefits such as integrating with the native app settings (so you can surface the same values in the iOS Settings app) as well as being a synchronous API (you don't need to do any Async calls to save or read the data values).




回答2:


The Xamarin Forms Application class has a built in cross platform way to save settings data like this, probably the easiest way unless you need something more. Take a look at Application.Properties and Application.SavePropertiesAsync



来源:https://stackoverflow.com/questions/37505210/the-best-way-to-save-configuration-data-in-xamarin-forms-based-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!