ViewModel Based Navigation, Maintaining State and OnSearchActivated

Topics: Getting Started, UI Architecture
Mar 31, 2013 at 9:58 AM
Hi, I'm working on my first app and I'm using C.M to get my head around MVVM. It's a simple media player for Win8 RT.

I've ended up using a ViewModel-based navigation pattern with a ShellViewModel/ShellView container for my other xaml. ShellViewModel inherits Conductor.

in App.xaml OnLaunched I call DisplayRootViewFor<ShellViewModel> and it all works fine. ShellViewModel also manages the navigation from page to page by call Activate<> for the various view models. ShellView also performs another role in that hosts a MediaControl which maintains state of songs that are playing as I navigate from page to page in the app. Because it's always open it means that once I starting playing a song it will continue to do so while I navigate around the app.

I upgraded the code to the new version of C.M this weekend and eventually got my head around the WinRTContainer. I have my ShellViewModel listed as a Singleton because I assume this means it won't reload.

In OnSearchActivated I simply want to:
  • load ShellViewModel if it isn't already loaded (Search charm is starting the app)
  • not touch ShellViewModel if its already loaded (potentially playing some songs at that moment)
And then call some function on it to pass in the search argument and have the ShellViewModel activate the SearchViewModel inside it as the new screen.

Any suggestions?

BTW, C.M is awesome. Thank you for your time.