Windows 8 roaming storage with custom class

I am learning programming in windows 8 using C #. I have worked many tutorials (such as http://msdn.microsoft.com/en-us/library/windows/apps/hh986968.aspx ) and I am trying to create a simple application showing a data warehouse. All the examples that I could find store only simple strings in roaming. Is there a way to store more complex data there?

example: List of base class A person with a name and age. I tried to do it like:

Saving data:

roamingSettings.Values ​​["peopleList"] = people;

Data loading:

people = (List) roamingSettings.Values ​​["peopleList"];

WinRT Information: An error occurred while trying to serialize the value that should be written to the application data store. when saving data, I get an error "Data of this type is not supported"

So, perhaps all you can save is string values, but I have not seen this anywhere.

+1
source share
1 answer

Yes, you can save your data values ​​as a collection. Solution to the problem   ApplicationDataCompositeValue class

Learn more about http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.applicationdatacompositevalue.aspx

As you mentioned, you are developing in C #, here is the code for your problem I thought you had a Person class with two members

class person
{
int PersonID;
string PersonName
}

Now, to read and write values ​​for this class, here is the code

Window InitializeComponent();,

Windows.Storage.ApplicationDataContainer roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings;

,

void write (Person Peopleobj)
{
Windows.Storage.ApplicationDataCompositeValue composite = new Windows.Storage.ApplicationDataCompositeValue();
composite["PersonID"] = Peopleobj.PersonID;
composite["PersonName"] = Peopleobj.PersonName;
roamingSettings.Values["classperson"] = composite;
}

Person,

void DisplayOutput()
    {
        ApplicationDataCompositeValue composite = (ApplicationDataCompositeValue)roamingSettings.Values["classperson"];

        if (composite == null)
        {
            // "Composite Setting: <empty>";
        }
        else
        {
        Peopleobj.PersonID = composite["PersonID"] ;
        Peopleobj.PersonName = composite["PersonName"];

        }

         }
+4

All Articles