在基于 Xamarin.Forms 的应用程序中保存配置数据的最佳方法?

问题描述:

我现在正在开发基于 Xamarin.Forms 的应用程序,对此几乎没有疑问.有没有最好的方法来保存一些配置数据?因为我正在使用基于 MVVM 的应用程序

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))
   }
}

我想在其他时候加载我的应用程序时使用它时保存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?

我目前建议不要使用 Xamarin Forms 的 Application.Properties 功能,因为它不是特别可靠,也不是特别灵活.相反,我建议使用跨平台设置插件(在 NuGet 上:https://www.nuget.org/packages/Xam.Plugins.Settings/ 和源代码/文档:https://github.com/jamesmontemagno/Xamarin.Plugins/tree/master/Settings),它提供了同样简单的 API,但没有 Application.Properties 的问题 功能.

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.

设置插件还有一些额外的好处,例如与本机应用程序设置集成(因此您可以在 iOS 设置应用程序中显示相同的值)以及作为同步 API(您不需要执行任何 Async调用以保存或读取数据值).

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).