I broke the time space continuum by passing complex para in navigation.

Aug 11, 2013 at 7:52 PM
Windows 8.1, VS 2013 Preview.

I have watched Brian's pluralsight course and use it as a reference on a regular basis.
If you have watched it, you know it contains a bunch of information to consume in one sitting.
It is not unusual for me to forget things that I have learned in a course, so when I was setting up my navigation between my first two pages, I forgot that we should only pass primitives between pages,
I just went ahead and passed my complex object as a parameter.

Category is a complex object with many properties including a Collection<Item>, Item is another complex object.
_navigationService.Navigate("Category", (Category)parameter);

Here I am catching the ball in the CategoryPage's onNavigatedTo
this.SelectedCategory = navigationParameter as Category;

Here I am binding to the SelectedCategories items collection in the xaml.
<CollectionViewSource x:Name="itemsViewSource" Source="{Binding SelectedCategory.Items}"/>

From the CategoryPage, here I am passing the selected Item to the ItemEditPage.
_navigationService.Navigate("ItemEdit", selectedItem);

And here I am receiving it in my vm's onNavigatedTo
this.SelectedItem = navigationParameter as Item;

And here is binding in the xaml.
<TextBox Text="{Binding SelectedItem.PurchasedFrom, Mode=TwoWay}"/>

This ALL works!
My question to the group here is, why is it working? Are the mice deep in the basement of 8.1 doing a better job of serializing?
Aug 12, 2013 at 6:50 PM

Based on my understanding, the problem with the navigation parameters is not during navigation itself, but during suspension. Basically, each navigation request you invoke will be saved in the navigation journal of the hosting Frame, which includes the parameters passed in each request. The Frame also allows you to serialize its journal so that it could be saved during suspension and reloaded when the application is resumed. This saving / reloading of the journal is done automatically by Prism.

When navigating, the "complex parameter" will be passed back and forward without issues, as no serialization is needed at this point, as far as I know. However, when the application is suspended the Frame will try to serialize its journal and fail, as it will not be able to serialize the complex object passed as a parameter. You can check this in you application when debugging, by navigating to the page where the complex parameter is received and suspending the application in visual studio.

Hope this helps,

Damian Cherubini
Aug 13, 2013 at 5:45 AM
Damian, thank you for pointing that out to me. I forgot that the importance of only passing primitive types was tied to serialization during suspend and resume.

Thanks again for clearing it up for me.