If you use Page-s in a Frame then you may want to handle Frame.Navigating and Navigated events in your pages' view models.

Here is a sample root model of your application:
public class RootModel
{
    public RootModel()
    {
        NavigationState = new NavigationState();

        HomePageModel = new HomePageModel();
    }

    public NavigationState NavigationState { get; set; }

    public HomePageModel HomePageModel { get; set; }

    public bool CanGoBack { get { return NavigationState.CanGoBack; } }

    public void GoBack()
    {
        NavigationState.GoBack();            
    }

    public void GoToHomePage()
    {
        NavigationState.Navigate(typeof (HomePage));
    }
}

Set the global DataContext in the Application derived class of your application:
sealed partial class App : Application
{
    ...
    public RootModel RootModel { get; private set; }

    protected override void OnLaunched(LaunchActivatedEventArgs args)
    {
        RootModel = new RootModel();

        var frame = new Frame { DataContext = RootModel };

        // Bind the NavigationState and the frame using the ElementBinder class.
        // You can also do this in XAML.
        ElementBinder.SetWrapper(frame, RootModel.NavigationState);

        Window.Current.Content = frame;
        Window.Current.Activate();

        RootModel.GoToHomePage();
    }
}

The home page model that handles navigation events:
public class HomePageModel : PageModel // Or implement IPageModel.
{
    public override void OnNavigated()
    {
        // TODO Do something here to initialize/update your page.
    }

    public override void OnNavigating(ref bool cancel)
    {
        // TODO Do something here to clean up your page.
    }
}

The HomePage page XAML:
<Page x:Class="YourNamespace.HomePage" ... DataContext="{Binding HomePageModel}">
    <!-- Your page content goes here -->
</Page>

Last edited Mar 13, 2013 at 5:28 PM by mglukhankov, version 5

Comments

Yvan Mar 10, 2013 at 3:51 PM 
How do you pass information when navigating from one page to the other?