- IOS: CFPreferences
- Droid: Preferences
- UWP: Application Data
PM> Install-Package Xam.Plugins.Settings
this Xamarin package abstracts the three platform specific solutions into a write once, use everywhere approach
- IOS:NSUserDefaults
- Droid: SharedPreferences
- UWP: IsoltatedStorageSettings/ApplicationDataContainer
This does limit us to our basic types with a string key
- Boolean
- Int32
- Int64
- Float
- Double
- Decimal
- Guid
- String
- DateTime
<?xml
version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:pav02.SimpleData"
x:Class="pav02.SimpleData.MainPage">
<StackLayout>
<Entry x:Name="FullName_ENTRY" Placeholder="full name"/>
<Button Text="Save" Clicked="Button_Clicked" />
</StackLayout>
</ContentPage>
using Plugin.Settings;
using System;
using Xamarin.Forms;
namespace pav02.SimpleData
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
var fullName = CrossSettings.Current.GetValueOrDefault("fullName", "");
FullName_ENTRY.Text = fullName;
}
private void
Button_Clicked(object sender,
EventArgs e)
{
var fullName = FullName_ENTRY.Text;
CrossSettings.Current.AddOrUpdateValue("fullName", fullName);
}
}
}