Create Navigation Based Application in WPF

This article will demonstrate how to create the Navigation Based Windows Application in WPF.

There are two types of windows applications the first one is Standard Windows Application which is normally the same old style Stand alone or some time we say Desktop based application. The second one is called as Navigation Based Application which is kind of the Web type application. The behavior is some what as the Wizard Type of application where you can navigate between the windows and perform the task.

The WPF has given the way to create the Web Page kind of Windows application, where one can navigate between the Window or Page controls.

Normally when you create the WPF Application the XAML creates the Window control and which has the Title, Width, Height and Windows Startup attribute as shown below


<Window x:Class="WpfApplication2.Window1" xmlns=""
 xmlns:x= Title="ListView" Height="350" Width="400" Loaded="Window1_Loaded">

But when you create the Navigation based application the control has the Page tag instead Window tag and it does can't have Title and few more properties/attributes. The Page tag looks like as below.


<Page x:Class="WpfApplication2.Window1" xmlns=""
xmlns:x= WindowHeight="300" WindowWidth="300">

Example  1: The below example show how to implement the Navigation based application. Basically once you put the Page tag, it will render the window with the Navigation Toolbar as shown in Figure 1.


<Page x:Class="wpfnavigationwindow_cs.Window1"



    WindowHeight="300" WindowWidth="300"



                   <TextBlock HorizontalAlignment="Center" FontSize="25">My First Navigation App</TextBlock>

                   <StackPanel Orientation="Horizontal">

                             <Image Source="IMG116.jpg" Width="100px"/>

                             <TextBlock HorizontalAlignment="Center">This is my Network..</TextBlock>



                             Go <Hyperlink NavigateUri="Page1.xaml">Here</Hyperlink> to go to Next Page.


                                      <Hyperlink NavigateUri="http://www./">Go to the Site</Hyperlink>






using System;

using System.Collections.Generic;

using System.Text;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Data;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Imaging;

using System.Windows.Shapes;


namespace wpfnavigationwindow_cs


          /// <summary>

          /// Interaction logic for Window1.xaml

          /// </summary>

          public partial class Window1 : System.Windows.Controls.Page


                   public Window1()







Figure 1

When you click on Here Link then it will navigate to Next Page as mentioned in the NavigationURI property of Hyperlink control.  The URI has the Page control (XAML) file and once you move the next page it will enable the Navigation Toolbar as shown in the Figure 2


<Page x:Class="wpfnavigationwindow_cs.Page1"





                   <TextBlock>This is Page 1.  Congratulations you made it.</TextBlock>



Figure 2

But the good practice to make the Navigation based application use the NavigationWindowinstead of Page control. As Page Control is mostly used for the Web Based Application and other benefit you can have the Window Control Properties. Now you can set the Title Property for the NavigationWindow.

Another benefit is you can set the Soruce which will open the Windows Control inside the NavigationWindow Control. The XAML page will look like


<NavigationWindow x:Class="wpfnavigationwindow_cs.Window2"



    Title="Here is my application" Height="300" Width="300" Source="Window1.xaml"



Note: The Source is set to the Window1.xaml, so it will open the window1.xaml inside the NavigationWindow

Now you can set the StartupUri attribute of App.xaml to Window2.xaml so the when you run the application it will open the NavigationWindow application.


<Application x:Class="wpfnavigationwindow_cs.App"