Windows Phone development path (15) basic navigation

Source: Internet
Author: User

In a slightly more complex application, multiple pages may be used. To jump to these pages, you must use the navigation function.

The following example provides a basic function: navigate from mainpage on the home page to secondpage, and then return to the mainpage from secondpage.

  Mainpage XAML code:

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<TextBlock Text="Navigate to Second Page!"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Padding="0,34"
ManipulationStarted="TextBlock_ManipulationStarted"/>
</Grid>

  Mainpage C # code:

Public partial class mainpage: phoneapplicationpage
{
// Constructor
Public mainpage ()
{
Initializecomponent ();
}

Private void textblock_manipulationstarted (Object sender, manipulationstartedeventargs e) // process the manipulationstarted event
{
// Todo: Jump to the secondpage page when you click textblock.
This. navigationservice. navigate (New uri ("/secondpage. XAML", urikind. Relative); // call the navigate () method of the navigationservice class to implement navigation

E. Complete (); // indicates that other manipulation events will not be processed.
E. Handled = true; // indicates that the route event has been handled and does not need to be passed up.
}
}

  

  Secondpage XAML code:

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<TextBlock Text="Go back to Main Page"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Padding="0,34"
ManipulationStarted="TextBlock_ManipulationStarted"/>
</Grid>

  Secondpage C # code:

Public partial class secondpage: phoneapplicationpage
{
Public secondpage ()
{
Initializecomponent ();
}

Private void textblock_manipulationstarted (Object sender, manipulationstartedeventargs e) // process the manipulationstarted event
{
// Todo: return to the main page
This. navigationservice. Goback (); // call the Goback () method of the navigationservice class to return to the previous page, which is equivalent to the next line of code.
// This. navigationservice. navigate (New uri ("/mainpage. XAML ", urikind. relative); // The difference is that the program will not return to the original mainpage instance, but will navigate to a new mainpage instance.

E. Complete ();
E. Handled = true;
}
}

Effect


Click textblock and navigate to the secondpage. Click textblock to return to the mainpage.

Note: 1. The manipulationstarted event occurs when the operation is performed on the uielement object (textblock here. Click it to happen immediately.
2. The navigationservice attribute is a read-only attribute defined in the page class. It is of the navigationservice type, and the navigationservice class is a seal class. We cannot instantiate it, create their own navigationservice instances by the host type. The navigationservice class includes the navigate () method and Goback () method.
3. Pay attention to this. navigationservice. goback () and this. navigationservice. navigate (New uri ("/mainpage. XAML ", urikind. relative), although they achieve the same effect, but their principles are different.

The next article will summarize the data transmission between pages in the Silverlight application.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.