.WithParam(s => ComplexType, x)

Topics: Getting Started
Aug 3, 2011 at 11:43 AM

Hi quick q

Should I be able to navigate to another view model passing a complex type as a parameter?

I can successfully navigate WithParams using primitive types but as soon as I try a complex type MyType or List<MyType> I get a funky error message saying

Invalid cast from 'System.String' to 'MyCustomType'

Any guidance would be much appreciated.

Aug 3, 2011 at 12:17 PM

No, you cannot do that out of the box. The parameters must be convertible to string because the WP7 navigation system only supports nav by Uri, so we have to convert the parameter to/from a query string parameter. You could possibly hack it to work by overriding ToString to return some sort of serialization, then plugging into the MessageBinder.CustomConverters to convert back from the string into the complex type. Perhaps I can consider making some formal way to do this in the future.

Aug 3, 2011 at 12:23 PM
Wow thanks for the quick response. I actually had already start playing around with overriding ToString() and decided it was probably to hackish.

Given you've confirmed my thought that it had something to do with QueryString parameters I've chosen to serialize to isolated storage on the tips of navigating between pages.