6
Vote

Support for complex objects as navigation parameter

description

In most of the applications, especially business applications, I think is very useful to pass complex objects as navigation parameter.
Since this feature is not supported by Frame control, why don't you json serialize the parameter before invoking frame Navigate method and deserialize it when invoking OnNavigated method of the viemodel?

In my application I'm doing in this way and everything is working fine. I'm considering to port my application to Prism framework and this feature is essential for me.

It also would be to have typed parameters in navigation service and in OnNavigated method of the viewmodel.

Thank you very much.

comments

blainew wrote May 19 at 9:26 PM

OasisLiveForever and/or ssd, can you give me a application scenario where you need to pass complex objects? The concern is if someone has a complex object graph that is passed as a parameter, it could affect perf during suspend & resume.

blaine

OasisLiveForever wrote May 20 at 4:03 AM

Hello,

a few examples:
  • In my app I have a page with a list of users. When I click on a user item, I go to view user profile page and then from this page I can go to edit user profile page. For both of these pages (view and edit profile) I pass the Id and also the Name of the user. In this way I immediately set the user name in the title of the page and then I load detail invoking a web service passing the user id. In this way I see a page with user name and a loader so I know which user is loading.
  • In the same app, from the list of users I have a button that shows a popup to create a new user. After creating the user I go to edit profile page (with additional fields not available during creation) instead of view profile page. Then if I save the user from edit profile page I go to view profile page. Now if I click back button I want to return to user list but t do this I have to remove edit profile page from history. I have to do this only when creating a new user since the navigation flow is different so I need to pass UserId, Name and IsNewUser to view and edit user profile pages.

OasisLiveForever wrote May 20 at 4:10 AM

Hello,

other examples:
  • In my app I have a page with a list of users. When I click on a user item, I go to user detail page. From this page I can navigate to sub pages and one of these is user history that shows user history grouped by content type. Sometimes I need to set select a specific content so I need to pass UserId and DefaultContent as page parameters.
  • In my app I have a page with a list of users where I can apply filters or search by text. Sometimes I need to navigate to this page passing default filters and default query text.

OasisLiveForever wrote Jun 11 at 3:37 AM

It seems that with Universal Apps you can pass complex objects in frame Navigate method.
I tried also in my WinRT app and now it works, I don't need anymore to JSON serialize the parameter.
Maybe it's a behavior change introduced by Visual Studio 2013 Update 2.

blainew wrote Jun 11 at 4:17 PM

Have you tried to Terminate and Resume your app after you passed a an object as a navigation parameter. That is the issue. I suspect you will get an exception.

OasisLiveForever wrote Jun 13 at 3:26 AM

You're right, even simply suspending the app I get an exception (I think when frame navigation state is saved on suspension).
So in order to pass complex parameter to a page I still have to JSON serialize the parameter.