Moving between screens in a platform independent way (PCL)

Topics: Actions & Coroutines, Conventions, Getting Started
Dec 30, 2013 at 10:04 PM
I'm trying to write my ViewModel's in a Portable Class Library (PCL), and then consume them in a Windows Phone 8 and a WinRT app. Looking around I decided to just check out Caliburn.Micro and use the most recent version as it looks like a huge amount of work has been done for Windows Store and PCL in general (btw, it looks really nice, I'm looking forward to using this).

The thing that has me stumped is how to move between screens or views in my ViewModel library. Say I have a "Create" button on a view, and when I click on it I'd like to bring up the "Create New Document" view. I have view models backing both of these. My original thought had been that when the Create() method I'd transition to the CreateNewDocumentViewModel. In my little test with a Windows Store app I just use INavagationService to do this. But I just discovered that was only available in the WinRT versions of CM. Is there something else I should be using that is more general and perhaps PCL compatible?
Dec 30, 2013 at 10:51 PM
I've now created a sample WP app just to experiment a bit (sorry, I should have done that before I posted). There is also a INavigationService there, but it is very different from the WinRT one.

Perhaps this is me not really understanding how you do things the Caliburn.Micro way - but wouldn't you normally want INavigationService to be in the ViewModel? So does it make any sense to unify some of the functionality so that it can be used in a cross platform PCL?

Many thanks!
Dec 31, 2013 at 10:11 AM
At the moment we are only at the beginning of our PCL story.
I tried to get as much working in PCL as possible.

A unified navigation system would be the next big step, but haven't found the time for it yet.
Every help in this area is appreciated.
Dec 31, 2013 at 5:22 PM
Thanks!

That makes sense. It is a lot of work to unify the interaction models! I guess there are two choices - another layer of abstraction or break backwards compatibility. Fortunately, I have the choice made for me, not being the library author.

In that spirit, I have started experimenting with the additional layer of abstraction. You can find the code here: https://github.com/gordonwatts/Caliburn.Micro.PCL. However, I am very new to all of this MVVM work, and also cross platform development! By new I mean less than a week. So I am feeling my way. For example, some of your navigation translates to Uri's and parameters (phone) and I have not hit a place in my own work where that is needed. So I still have a lot to learn.

BTW, I discovered a clever trick in Paul Betts' ReactiveUI library to reduce the code for a backing property that raises notifications. I also shoved it into that library above as it makes my ViewModels much nicer without have to use an Il rewrite.

Happy New Year, and thanks for all the careful work that you and the other contributors have done on the library. Makes it possible for a beginner like me to get up and running much faster that it might be possible otherwise!