Hi,
I'm Serializing a ObservableCollection:
I'm guessing this is how it works?:
I'm Serializing a ObservableCollection:
private ObservableCollection<Models.WorkSenario> workingSenarios;
public ObservableCollection<Models.WorkSenario> _WorkingSenarios
{
get { return this.workingSenarios; }
set
{
SetProperty(ref this.workingSenarios, value);
}
}
...my class:[System.Runtime.Serialization.DataContract(Name = "WorkSenario")]
public class WorkSenario
{
public Models.WritingMenu WorkingSenario { get; set; }
public int MainViewId { get; set; }
public CoreDispatcher MainDispatcher { get; set; }
public CoreDispatcher Dispatcher { get; set; }
public CoreWindow Window { get; set; }
[System.Runtime.Serialization.DataMember]
public string Title { get; set; }
public int ViewId { get; set; }
[System.Runtime.Serialization.DataMember]
public bool Released { get; set; }
[System.Runtime.Serialization.DataMember]
public bool Consolidated { get; set; }
}
...using:/// <summary>Serializes an object and write to file in specified storage strategy</summary>
/// <typeparam name="T">Specified type of object to serialize</typeparam>
/// <param name="key">Path to the file in storage</param>
/// <param name="value">Instance of object to be serialized and written</param>
/// <param name="location">Location storage strategy</param>
public static async Task<bool> WriteFileAsync<T>(string key, T value, StorageStrategies location = StorageStrategies.Local)
{
// create file
var _File = await CreateFileAsync(key, location, Windows.Storage.CreationCollisionOption.ReplaceExisting);
// convert to string
var _String = Serialize(value);
// save string to file
await Windows.Storage.FileIO.WriteTextAsync(_File, _String);
// result
return await FileExistsAsync(key, location);
}
..and was wondering if this does the same thing:protected override void OnRegisterKnownTypesForSerialization()
{
// Set up the list of known types for the SuspensionManager
.
..
...
SessionStateService.RegisterKnownType(typeof(Product));
SessionStateService.RegisterKnownType(typeof(Collection<Product>));
}
...for the class:public class Product
{
public string ProductNumber { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public Uri ImageUri { get; set; }
public int SubcategoryId { get; set; }
public double ListPrice { get; set; }
public double DiscountPercentage { get; set; }
public double Weight { get; set; }
public string Color { get; set; }
public string Currency { get; set; }
}
..without using a DataContract, because I want to use all of Prism's built in capabilities before using standard coding. Secondly) would explain how this works please?I'm guessing this is how it works?:
public class SearchResultsPageViewModel : ViewModel
{
.
..
...
[RestorableState]
public static Collection<Product> PreviousResults { get; private set; }
Thanks!...