How to store App settings in Xamarin.Forms

后端 未结 4 2072
攒了一身酷
攒了一身酷 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:10

    I use Settings Plugin for Xamarin And Windows for Xamarin.Forms, the upside since this is implemented at the device-level, you can access these settings from any Forms project, PCL library OR your native project within your app.

    • Nuget: Xam.Plugins.Settings

    private const string UserNameKey = "username_key";
    private static readonly string UserNameDefault = string.Empty;
    

    public static string UserName
    {
      get { return AppSettings.GetValueOrDefault(UserNameKey, UserNameDefault); }
      set { AppSettings.AddOrUpdateValue(UserNameKey, value); }
    }
    

提交回复
热议问题