问题
I am new to xamarin forms. I am working on an app with 3 pages. One of the pages has a listview. Clicking on a row takes you to another page. I want to make this available for authenticated users only. You have to be logged in to use this feature.
I have been looking online and no luck. Is there anything like session in xamarin forms? Is there anything I can use for storage which all pages can have access to?
Any ideas/link will be appreciated
回答1:
As Jason mentions, use Application.Current.Properties dictionary to store key pair values.
https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/application-class/#Properties_Dictionary
Fairly simple and doesn't require an additional dependency like Xam.Plugins.Settings.
回答2:
There's a cross platform settings plugin available from the Xamarin Component Store or as a nuget package. It's free and easy to use.
https://www.nuget.org/packages/Xam.Plugins.Settings/
It's as easy as creating a "Settings" class and then creating a getter and setter for your value like this:
public static bool Authenticated
{
get { return AppSettings.GetValueOrDefault<bool>(AuthenticatedKey, AuthenticatedDefaultValue); }
set { AppSettings.AddOrUpdateValue<bool>(AuthenticatedKey, value); }
}
It's well worth a look and super easy to implement for simple adhoc storage of values.
来源:https://stackoverflow.com/questions/45964321/xamarin-forms-global-storage