Reputation: 320
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
Reputation: 990
You need to deserialize yourself
protected override void OnNavigatedTo(NavigationEventArgs e)
{
string myString = Template10.Services.SerializationService.SerializationService.Json.Deserialize<string>(e.Parameter?.ToString());
}
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.
Template10.Common.BootStrapper.Current.NavigationService.Navigate(typeof(PageToNavigateTo), objectToSerialize);
[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