Page Navigation in Windows Phone

By | March 16, 2012

Hello everyone…

This is my first post on windows phone. I have just started windows mobile programming.
In this post I will show you how to go from one Page to another in windows.

First I am creating a C# project and in the MainPage.xaml

Open the phone interface and then drag a button into it. Double click on the button and write this code inside it.

  this.NavigationService.Navigate(new Uri("/Page1.xaml", UriKind.Relative));

Here is the complete code in MainPage.xaml

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

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

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            this.NavigationService.Navigate(new Uri("/Page1.xaml", UriKind.Relative));
        }
    }
}

Now right click on the solution explorer root and add->existing item , then add a portrait page. Then name it Page1.xaml

here is the code inside the Page1.xaml

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace PhoneApp1
{
    public partial class Page1 : PhoneApplicationPage
    {
        public Page1()
        {
            InitializeComponent();
        }
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *