programming4us
programming4us
MOBILE

Windows Phone 7 : Working with Controls and Themes - Understanding Frame and Page Navigation

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
To navigate from screen to screen in a Windows Phone 7 application, an understanding of the PhoneApplicationFrame and PhoneApplicationPage controls is important. There is only one PhoneApplicationFrame available to a Windows Phone 7 application; this frame reserves space for the System Tray and the Application Bar, as well as the content area where PhoneApplicationPage controls live. You can create as many different pages as needed and then navigate to those pages from the frame. See Figure 1 to see how the controls are placed in the phone.
Figure 1. PhoneApplicationFrame and PhoneApplicationPage

To navigate from page to page within your application, use the NavigationService class. This class exposes methods to navigate to pages given a URI, as well as to go back to the previous page. The following walkthrough illustrates the use of the NavigationService class.

1. Creating a User Interface for NavigationTest Project

The NavigationTest project will contain two XAML pages (MainPage.xaml and Page1.xaml) and will navigate between the two.

  1. Launch Visual Studio 2010 Express and select the Windows Phone Application template. Change the Project Name to "NavigationTest," select OK, and Visual Studio will set up a new project.

  2. Right-click the project name in Solution Explorer and select Add => New Item => Windows Phone Portrait Page. Accept the default name of Page1.xaml and press OK.

  3. Open MainPage.xaml in Design View. From the toolbox, drag and drop the HyperlinkButton control. With that control selected, press F4 to display its properties and change the Contents to be "Go to Page1."

  4. Open Page1.xaml in the design view, and add a button to that page from the toolbox. Edit the Contents of the button to say "Go Back to MainPage."

  5. Add a TextBlock underneath the button on Page1.xaml. This TextBlock will be used to show the parameters passed in to this page.

In the next section, we will use NavigationService to navigate between pages.

2. Adding Navigation Code

When the user clicks the "Go to Page 1" hyperlink, you will be using NavigationService to move to Page1.

  1. Open MainPage.xaml and double-click the hyperlink on that page. Implement the hyperlinkButton1_Click event handler with the following code:

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

    }

  2. Open Page1.xaml and double-click the button on that page. Implement the button1_Click event handler with the following code:

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

  3. Press F5 to run the application. Now when you click the hyperlink on MainPage.xaml, you are taken to Page1.xaml. When you click the button on Page1.xaml, you are taken back to MainPage.xaml. In the next section, we will enhance this application slightly to pass parameters between the pages.

3. Adding Code to Pass Parameters Between Pages

In the previous section, you learned how to successfully navigate from page to page. In this section, you will see how you can pass parameters from one page to another.

  1. Open MainPage.xaml.cs and change the hyperlinkButton1_Click event handler to the following:

    private void hyperlinkButton1_Click(object sender, RoutedEventArgs e)
    {
    NavigationService.Navigate(new Uri("/Page1.xaml?message=Hello,World",
    UriKind.Relative));
    }


Here, you are passing the hard-coded string "Hello, world" to Page1.xaml for processing.

  1. In Page1.xaml, you will try to read the query string passed from the prior pages to see if there are non-empty values. Open Page1.xaml.cs and add the following code to that file:

    protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs
    e)
    {
    base.OnNavigatedTo(e);
    string msg = "";
    if (NavigationContext.QueryString.TryGetValue("message", out msg))
    textBlock1.Text = msg;
    }


  2. Press F5 to run the application. Now, if you press the hyperlink from MainPage.xaml, you should see the "Hello, world" message displayed on Page1.

Other  
  •  Windows Phone 7 : Working with Controls and Themes - Panorama and Pivot Controls
  •  Programming the Mobile Web : Widgets and Offline Webapps - Platforms (part 5) - Windows Mobile & BlackBerry
  •  Programming the Mobile Web : Widgets and Offline Webapps - Platforms (part 4) - Windows Mobile & BlackBerry
  •  Programming the Mobile Web : Widgets and Offline Webapps - Platforms (part 3) - webOS & Android
  •  Programming the Mobile Web : Widgets and Offline Webapps - Platforms (part 2) - iPhone, iPod, and iPad
  •  Programming the Mobile Web : Widgets and Offline Webapps - Platforms (part 1) - Symbian/Nokia
  •  Programming the Mobile Web : Widgets and Offline Webapps - Standards
  •  Mobile Application Security : BlackBerry Security - Networking
  •  Mobile Application Security : BlackBerry Security - Local Data Storage
  •  Themes on Windows Phone 7 Devices (part 2) - Changing the Theme & Detecting the Currently Selected Theme
  •  
    Top 10
    Free Mobile And Desktop Apps For Accessing Restricted Websites
    MASERATI QUATTROPORTE; DIESEL : Lure of Italian limos
    TOYOTA CAMRY 2; 2.5 : Camry now more comely
    KIA SORENTO 2.2CRDi : Fuel-sipping slugger
    How To Setup, Password Protect & Encrypt Wireless Internet Connection
    Emulate And Run iPad Apps On Windows, Mac OS X & Linux With iPadian
    Backup & Restore Game Progress From Any Game With SaveGameProgress
    Generate A Facebook Timeline Cover Using A Free App
    New App for Women ‘Remix’ Offers Fashion Advice & Style Tips
    SG50 Ferrari F12berlinetta : Prancing Horse for Lion City's 50th
    - Messages forwarded by Outlook rule go nowhere
    - Create and Deploy Windows 7 Image
    - How do I check to see if my exchange 2003 is an open relay? (not using a open relay tester tool online, but on the console)
    - Creating and using an unencrypted cookie in ASP.NET
    - Directories
    - Poor Performance on Sharepoint 2010 Server
    - SBS 2008 ~ The e-mail alias already exists...
    - Public to Private IP - DNS Changes
    - Send Email from Winform application
    - How to create a .mdb file from ms sql server database.......
    programming4us programming4us
    programming4us
     
     
    programming4us