Forum Cross Platform with Xamarin


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Issues using the Settings Component

LukeConnerLukeConner USMember, University ✭✭
edited October 2015 in Cross Platform with Xamarin

I didn't see an area specifically for components, and this applies to our Android and iOS app, so I'm putting this here.

I'm using the settings component to save username and password info. Based on their example I have the following class:
` public static class Settings
private static ISettings AppSettings
return CrossSettings.Current;

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

    private const string PasswordKey = "";
    private static readonly string PasswordDefault = string.Empty;

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

    public static string Password
        get { return AppSettings.GetValueOrDefault(PasswordKey, PasswordDefault); }
        set { AppSettings.AddOrUpdateValue(PasswordKey, value); }

I retrieve the username and password with just this:
string UserName = Settings.UserName; string Password = Settings.Password;

and set the username / password with this:
Settings.UserName = Email.Text; Settings.Password = Password.Text;

I can see that it gets passed the username and password, but when it returns the values I end up getting the username back for both values. I fell like it's something really simple that I'm not seeing here.


  • DavidStrickland0DavidStrickland0 USMember ✭✭✭

    If these are the Keys your using then it might be as simple as.

    private const string UserNameKey = "UserNameKey";
    private const string PasswordKey = "PasswordKey";

    Cause at the moment it looks like your using the same key "" for both.

  • LukeConnerLukeConner USMember, University ✭✭

    Well that did it. I don't think I completely understand why, but it worked.

Sign In or Register to comment.