简体   繁体   中英

How to save IsolatedStorageSettings key to a string

I'm making a project for windows phone 8 using C# and I want to be able to save some strings to storage so the next time the user opens the app, He'll be able to have the strings he saved last time he opened it.

I set it like this:

IsolatedStorageSettings.ApplicationSettings["key"] = SetKey.Text;

and I try to get it like this:

if (IsolatedStorageSettings.ApplicationSettings.Contains("key"))
{
    string GetKey = (string)IsolatedStorageSettings.ApplicationSettings["key"];
}

SetKey is the name of a TextBox.

The problem is that when I run this I get an unhandled exception at the code line that is in the if, saying:

An exception of type 'System.InvalidCastException' occurred in ProjectName.DLL but was not handled in user code.

if (IsolatedStorageSettings.ApplicationSettings.Contains("key") && 
        IsolatedStorageSettings.ApplicationSettings["key"] != null)
{
    string GetKey = IsolatedStorageSettings.ApplicationSettings["key"].ToString();
}

Try like this ! Probably key is null.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM