Mullaly
Mullaly

Reputation: 320

Template 10 Navigation Service Serialization

I am using Template10 for my UWP project. When passing a parameter while navigation, I can receive a serialized text of my object at my OnNavigated(NavigationEventArgs e).

This is because on calling Navigate method, Template10 navigation service serializes the object. Do I have to deserailize every-time passing a parameter to Navigation service. Is there any alternative?

Upvotes: 1

Views: 685

Answers (1)

user2921851
user2921851

Reputation: 990

In view page:

You need to deserialize yourself

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    string myString = Template10.Services.SerializationService.SerializationService.Json.Deserialize<string>(e.Parameter?.ToString());
}

In view-model page:

Deserialization is done for you; just cast the parameter object to the expected Type.

public override Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary<string, object> state)
{
    string myString = parameter?.ToString();
}

Remember that there is a data size limit (about 8kb?) you can serialize into Navigation service.

In view page:

 Template10.Common.BootStrapper.Current.NavigationService.Navigate(typeof(PageToNavigateTo), objectToSerialize);

In view-model page:

[Template10.MvvM.ViewModelBase.]NavigationService.Navigate(typeof(PageToNavigateTo), objectToSerialize);

For big chunk of data you've to seek an alternative solution such as session cache or something similar.

Upvotes: 2

Related Questions