Page Navigation in Windows Phone Application with XAML

In windows phone application page navigation is quite simple to perform. It can be easily explained with an example:


Create a simple blank windows phone project and on the main page add a TextBlock and a Button as shown below

navigation image


Now add a second page blank page to your project. As like the main page here on the second page you have to add a TextBlock and a Button. you can see this on the image below:



When you have done with this, now its the time to play with the event handlers for the both Buttons on first and second page.

You have to write the following code in the event handler for the first page button as:

namespace NavigationBetweenPages
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
        }

        private void navigate_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/SecondPage.xaml", UriKind.Relative));

        }

    }
}

Now here comes the turn of Button on  the second page and for which the code is as follows:



namespace NavigationBetweenPages
{
    public partial class SecondPage : PhoneApplicationPage
    {
        public SecondPage()
        {
            InitializeComponent();
        }

        private void back_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.GoBack();

        }
    }
}


Now you can enjoy the navigation to and from between the pages.

Page Navigation in Windows Phone Application with XAML Page Navigation in Windows Phone Application with XAML Reviewed by Afsar Murad on 00:10 Rating: 5
Powered by Blogger.