WinRT navigation service

Topics: UI Architecture
Dec 6, 2012 at 6:50 AM

I'm trying to implement a Hierarchical navigation and a Flat one in the same app.


Basically this: The top Bar has menu items (1 or more) and when selected it starts a hierarchical navigation.  


So is it possible to replace the INavigationService that is passed around each ViewModel?

I'm guessing I would need to create a new FrameAdapter with a new Frame, but then how do I tell the WinRTContainer to use that new one INSTEAD of the one created at startup?


Of any other ideas ?

Dec 10, 2012 at 8:06 PM

I've done a very simple version of this which had a root view where part of the page the Frame.

To do this I used a view model first approach (with DisplayRootViewFor<MainViewModel>) so that a Frame ISN'T created at startup leaving you free to create your own.

Later on the MainView had an embedded Frame control which when the view loaded I registered a new FrameAdapter with the WinRTContainer. This way I didn't have conflicting INavigationService.

Hope this helps.

Dec 21, 2012 at 1:54 AM

Hi Nigel,

I've tried to do exactly what you have specified - use ViewModel first navigation to navigate to a ShellViewModel + ShellView which has a frame on it, which I then register with my container to build the navigation service. Once the ShellView fires ViewLoaded, I then use Navigate to navigate the subframe to the first View of the application (OverviewView).

The problem is though that the new View seems to be attached to my ShellViewModel still - the overrides on my ShellViewModel are fired, not my OverviewViewModel.

Did you have to change anything within the ViewModelLocator to get this working?



Dec 21, 2012 at 6:03 AM

Sorry about that forgot one little detail. 

Because the Frame control lives within the ShellView it "inherits" ShellViewModel as it's DataContext. The binding Caliburn implements between view and view model will abort if it detects the existence of a view model, so it's this ShellViewModel that get's in the way.

The simplest way to get around this is to explicity set the datacontext of the Frame to null. This stops shell view model cascading into the page.

<Frame x:Name="InfoFrame" DataContext="{x:Null}" />