What I want: I'm trying to store complex data types in roaming settings. This is how my object looks like:

public abstract class Query
{
    [DataMember]
    public Cube Cube { get; private set; }

    [DataMember]
    public List<Filter> Filters { get; private set; }
    [DataMember]

    public Slicer Slicer { get; set; }
}

What is the problem:

Query q = ...;
RoamingSettings.Values["query"] = q;

is giving an error:

Data type not supported

What I have tried: Storing different members of Query class in different fields of composite settings. But the data members of Query class are again objects of different classes and hence cannot be stored in composite.Values["setting"].

Please refer: windows 8 app roaming storage with custom class. That question was answered by using the composite setting but is not applicable to mine.

How do I proceed?

有帮助吗?

解决方案

Ankush,

Looks like you are trying to shove a collection of custom objects into RoamingSettings, which is not quite what it is meant for. Local/Roaming Settings are stored usually in Registry and meant for simple name-value pairs.

How about this - you take your entire object model and flatten it out for storage as a File? This way, you can easily serialize/deserialize your data and hydrate/dehydrate your object model in your App when needed. Also, the flattened content can be saved in the Roaming Folder for syncing across multiple user devices. Simply annotate your custom object properties as needed and use the DataContractSerializer to flatten/unflatten your data and persist an XML file in Roaming Folder. Just do not depend on an instant cloud sync; Windows will sync the file in Roaming Folder opportunistically.

This MSDN quickstart should help:

http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh700362.aspx

Thanks!

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top