#14 – Page-Based Navigation

WPF applications can be structured as a collection of pages, with built-in navigation between pages.  This is different from the more traditional (Win Forms) document-based model, where the application displays a main window and dialogs that pop up.

To create a page-based application, you use a Page object as the top-level container in your application, instead of Window.

<Page x:Class="WpfApplication7.Page1"
      mc:Ignorable="d"  d:DesignHeight="300" d:DesignWidth="300"
        <Label Content="This is a page, not a window." Height="28" HorizontalAlignment="Left" Margin="52,75,0,0" Name="label1" VerticalAlignment="Top" />

To make this page the main object loaded when the application starts, set the StartupUri attribute of your main Application:

<Application x:Class="WpfApplication7.App"

Notice that we now get a main window with navigation controls at the top.


About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

3 Responses to #14 – Page-Based Navigation

  1. Diana says:

    But how to navigate between pages?

  2. Vladimir says:

    To navigate from one page to another one way that I found is to use a button. In the codebehind you add using System.Windows.Navigation; so you can use the navigation control

    private void Button_Click(object sender, EventArgs e)
    this.NavigationService.Navigate(new Uri(“Menu.xaml”, UriKind.Relative));

    The Uri is the .xaml file that you want to go to and if the file is in a folder you add the folder for example “MenuGroup/Menu.xaml”. Works from a window to a page, but if you want to call a window from a page you can use the folowinf snippet:

    private void RegisterProfile_Click(object sender, EventArgs e)
    new RegisterProfile().Show();

    Where RegisterProfile is the name of the window that you want to call, and if it is in a folder you add the full path for example “new ProfileGroup.RegisterProfile().Show();”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: