FAQ | Preferences
James Montemagno edited this page Oct 2, 2018
·
4 revisions
Here are some common questions about the Preferences API:
When you developing with Xamarin.Forms you may want to use data binding with a preference. For example you may have a switch that is bound to a boolean:
<Switch IsToggled="{Binding IsActive, Mode=TwoWay}"/>
In your ViewModel you could write a property that uses the Preferences API to get, set, and raise a property notification:
const string ActiveKey = "is_active_key";
public bool IsActive
{
get => Preferences.Get(ActiveKey , false);
set
{
if (IsActive == value)
return;
Preferences.Set(ActiveKey , value);
OnPropertyChanged(nameof(IsActive));
}
}