4
votes

I'm trying to figure out how to successfully get Caliburn Micro to navigate from one page to another in a Windows Phone 8.1 app.

My first page loads just fine, as specified in my App class:

protected override void OnLaunched(LaunchActivatedEventArgs args)
{
    this.DisplayRootViewFor<HomeViewModel>();
}

This launches the HomeView without issue. On that view I have a button that calls the following method:

public void GoToPage2()
{
    this.navigationService.NavigateToViewModel<Page2ViewModel>();
}

This method is called when the button is pressed and the constructor for Page2ViewModel is called as well. The page just never displays and I can't figure out why. I feel like I'm missing a core concept, but I can't find any examples of how this should work.

Thanks for any help.

1
Have you read this article? wp.qmatteoq.com/… - Igor Ralic
I have and while it is informative, it doesn't solve my problem. I have a view model that inherits from Screen and it is instantiated and OnActivate is called. It's just that the view never appears on the screen. - Brian Vallelunga
Do you have a Page2View? - mvermef
Yes, I have a Page2View. See my answer below. - Brian Vallelunga

1 Answers

5
votes

The solution is odd, and perhaps a bug in Caliburn Micro. In the OnLaunched method I used to have:

protected override void OnLaunched(LaunchActivatedEventArgs args)
{
    this.DisplayRootViewFor<HomeViewModel>();
}

This worked and launched the home view, but subsequent navigation never worked. After comparing to a sample application I found, I changed the code to:

protected override void OnLaunched(LaunchActivatedEventArgs args)
{
    this.DisplayRootView<HomeView>();
}

This also displays the home view, but now subsequent navigation works! I'm not sure why this would be the case, but at least I have an answer.