views:

38

answers:

1

How does one pass a complex object to the target Page using the NavigationService.Navigate method?

+1  A: 

Unfortunately you can't do that. It kind of makes sense, because the idea is to provide deep linking support for pages/views, but it's definitely annoying that you can't do it. The options you have are:

  • For small objects, you could serialise them and pass them to the next view in the query string, although I'd recommend against that approach (different browsers have different number of maximum characters in a URL that they support, and also the object may be out of date if the user bookmarks that page and returns to it).

  • Store the object in a global cache, from which the view being navigated to can access it. Not nice, but it will work.

  • The Navigation Framework source code is a part of the Silverlight Toolkit. You could modify this to support complex objects, but I'd strongly recommend against doing so.

  • Use the MVVM pattern, with one view model used to manage multiple views, and therefore the object would be available to all those views.

Hope this helps...

Chris

P.S. I discuss this in my book Pro Business Applications with Silverlight 4, although only in as much depth as above as there's not a particularly nice solution to the problem :).

Chris Anderson
@Chris, Great book by the way. In this particular case, I ended up taking option 2, although not happy about it.
Ralph Shillington