Windows Phone Development (7): When Good master rudder

Source: Internet
Author: User

Tags: home textbox gif Click ROM his needs new CTI

After blowing the page about the topic, today we will talk about how the page is navigated, in more cases, our application will not have only one page, there should be N, as we do desktop application development, we may have more than one form in an application (except for very simple programs), We're going to handle the switching between the forms; Similarly, in web development, our Web application may also have more than one page, and we will handle the switch between pages. Of course, in our mobile phone application, we also need this kind of operation, we call it "navigation", as a developer, we control the switch between pages, so we are the "master rudder" of the app.

first, how to navigate. A simple way to navigate the page is to use the NavigateUri property of the Hyperlinkbutton control to specify the URI of the XAML file for the target page you want to navigate, and let's try it out in a simple example.

Create a new WP application project, put a Hyperlinkbutton control in the main page, set the value of NavigateUri to/pagesecond.xaml, and then create a new page named Pagesecond.xaml.

    1. <hyperlinkbutton content= "Skip to Page two" height= "horizontalalignment=" left "margin=" 126,86,0,0 "Name=" HyperlinkButton1 "verticalalignment=" Top "width=" 216 "fontsize=" "fontstyle=" normal "fontstretch=" normal "
    2. navigateuri= "/pagesecond.xaml"/>


The second navigation method is implemented in code, such as a button's Click event.

    1. private void Button1_Click (object sender, RoutedEventArgs e)
    2. {
    3. This. Navigationservice.navigate (New Uri ("/pagesecond.xaml", urikind.relative));
    4. }

second, Onnavigatedfrom method and Onnavigatedto method. 1. When the user is about to leave the current page, the Onnavigatedfrom method is called, 2, and the Onnavigatedto method is called when the user navigates to the page from another page. I believe you can write some code test, this is very good understanding. A. Add the following code to the main page.
    1. Leave the main page
    2. protected override void Onnavigatedfrom (System.Windows.Navigation.NavigationEventArgs e)
    3. {
    4. Base. Onnavigatedfrom (e);
    5. System.Diagnostics.Debug.WriteLine ("* * * * * * has left the main page. ");
    6. }


B. Add the following code to the second page.

    1. Navigate to a second page
    2. protected override void Onnavigatedto (System.Windows.Navigation.NavigationEventArgs e)
    3. {
    4. Base. Onnavigatedto (e);
    5. System.Diagnostics.Debug.WriteLine ("* * * * * Hi, has come to the second page. ");
    6. }

Then, you run the program to navigate and see what's in the Output window?

Third, how to pass the parameters between pages.

In Android development, from one activity to another activity, you need to intent object to pass content, but in WP development, we only need to like a Web page in the URI appended to the parameters.

such as:/NUMBB.XAML?PT1=AAAA&PT2=CCCCC.

Now, let's change the example we just made, put a textbox on the main page, and we'll pass the input on this page to the second page.

    1. private void Button1_Click (object sender, RoutedEventArgs e)
    2. {
    3. This. Navigationservice.navigate (New Uri ("/pagesecond.xaml?str=" + TextBox1.Text, urikind.relative));
    4. }


Remove the data from the second page. Remove the data from the second page.

    1. Navigate to a second page
    2. protected override void Onnavigatedto (System.Windows.Navigation.NavigationEventArgs e)
    3. {
    4. Base. Onnavigatedto (e);
    5. What is the name of the passed argument, and what is the name to be taken here?
    6. String PV = this. navigationcontext.querystring["str"];
    7. This.textBlock1.Text = PV;
    8. }


Windows Phone Development (7): When Good master rudder

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.

Tags Index: