Passing complex objects

Topics: Getting Started
May 3, 2013 at 7:13 PM
Hello everyone,

I just started with Caliburn Micro and loving it so far. I'm not that familiar with MVVM (other than the theory). The biggest problem I ran into is passing complex objects. I'm using INavigationService for most of my navigation (which doesn't support passing complex objects).

I've looked around on the web and although several solutions were proposed a lot of them involved writing a lot of custom code and not all of them were looking very clean, so I'm thinking there must be a simpler way.

At the moment I'm using INavigationService service and passing my complex object as an xml string and deserializing it in the second ViewModel, but this is a bit dirty of course :)

Can anyone give or point me to a (noob friendly) explanation on how to do this ? Something straight forward ?

Thanks,

Jorn
May 4, 2013 at 4:11 AM
before I get long winded I am assuming WP7/8 or RT? That link might help.

https://caliburnmicro.codeplex.com/discussions/393238
May 4, 2013 at 10:32 AM
Thanks for the reply !

It's WP8. From what I read in that thread it is possible in WinRT but not in WP8 and there's some discussion if it's still coming ?
May 5, 2013 at 4:05 AM
no because the limitation with how WP7/8 do navigation is done through QueryString passing gross amounts of data is hard.

One of the options is to pass just the index value for the object in question (assuming database)

_navService.UriFor<ViewModelObject>().WithParameter((p)=>p.SomeProperty, Property.Value).Navigate(); // example

Second is to try is the PhoneApplicationService.Current.State object and push the object into a variable like

var state = PhoneApplicationService.Current.State;

state["someobject"] = someobject; then just pull state["someobject"] out in the other screen.

someobject = state["someobject"]; // from previous screen
May 5, 2013 at 10:16 AM
Hello,

It's from a web service, which doesn't allow you to get an object by ID, just the list. But your second proposal looks great, I'll give that one a shot somewhere this week (busy days at the moment :))

Thanks !

Jorn
May 5, 2013 at 11:19 PM
Edited May 5, 2013 at 11:20 PM
if its a webservice you might want to look at odata depending on the recent tech that it uses.
May 6, 2013 at 8:39 PM
Hello,

I can confirm your proposed solution works beautifully, thanks for that :)

It's a java rest service that I'm connecting to. We have some odata services but not for this.

Thanks a lot for your suggestion, it really helped me :)

Jorn