Windows Phone page navigation (6)

Source: Internet
Author: User
Tags baseuri

In the example of page navigation, we use two pages, from the first page (mainpage) to the second page (secondpage), and then we can navigate from the second page to the first page, OS 7.1 used;

The page navigation does not introduce the new namespace. The property used by the new namespace is derived from the phoneapplicationpage class;

The code used in the mainpage. XAML file is:

<Grid X: Name = "contentpanel" grid. Row = "1" margin = "12,0, 12,0"> </GRID>
<Textblock X: Name = "navigation" text = "navigate to the second page" grid. row = "1" verticalalignment = "center" horizontalalignment = "center" manipulationstarted = "navigation_manipulationstarted"> </textblock>
</GRID>

The hidden file code is:

// textblock navigation time
         private void Navigation_ManipulationStarted (object sender, ManipulationStartedEventArgs e)
         {
             // why must be relative--knowledge points①
             this.NavigationService.Navigate (new Uri ("/ SecondPage.xaml", UriKind.Relative));

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

         protected override void OnManipulationStarted (ManipulationStartedEventArgs e)
         {
             // Knowledge points②
             SolidColorBrush scb = new SolidColorBrush ();
             // Knowledge points③
             Color color = new Color ();
             color.A = (byte) 245;
             color.R = (byte) 135;
             color.G = (byte) 25;
             color.B = (byte) 15;
             scb.Color = color;

             ContentPanel.Background = scb;
             base.OnManipulationStarted (e);
         }


The code for hiding a file is added with the above two methods based on the default code. The effect is that when you click (touch) A textblock element not named navigation, contenpanel will change to the set fixed color, mainpage:

 

Knowledge Point ①: This. navigationservice. navigate () is the core method parameter of page navigation. It is a URI-type object. Therefore, the new class is required and secondpage is used when the URI is instantiated. there is a diagonal line before XAML, and the second parameter indicates that this URI is relative to secondpage. XAML, the absolute URI refers to the complete reference of a resource such as: the relative uri of the http://www.sensengo.com/Index.html depends on
Uri (for example:/index.html)

 

The URI constructor contains a base Uri and a relative URI string:

Uri (Uri, string)

Based on the specified base Uri and relative URI
String, initialize URI
New instance of the class

Instance:

Uri baseuri = new uri ("http://www.contoso.com ");
Uri myuri = new uri (baseuri, "catalog/shownew.htm ");

 

Therefore, the URI instance constitutes an absolute Uri, And the myuri. tostring () string is: http://www.contoso.com/catalog/shownew.htm


Knowledge Point ②: The solidcolorbrush class is used to draw solid color areas. Another Construction Method of solidcolorbrush is: solidcolorbrush (color). Therefore, the above Code can also be implemented as follows: contenpane. backgroud = new solidcolorbrush (

Color. fromargb (245, (byte) 135, (byte) 25, (byte) 15 ));

Knowledge Point ③: Color here is the color set color of the solidcolorbrush attribute. The color class depicts an argb color. The color of each pixel in an image is represented as a 32-digit number: use 8 bits to represent Alpha, red, green, and blue (argb ).
The values of these four components are from 0 to 255. 0 indicates no brightness, and 255 indicates the maximum brightness.
The Alpha component specifies the transparency of the color. 0 indicates full transparency, and 255 indicates full opacity. Determine the alpha, red, green, or blue color.

 

Main Code of the secondpage. XAML file:

<Grid X: Name = "contentpanel" grid. Row = "1" margin = "12,0, 12,0"> </GRID>
<Textblock X: Name = "navigation" text = "navigate to the-th page" grid. row = "1" verticalalignment = "center" horizontalalignment = "center" manipulationstarted = "navigation_manipulationstarted"> </textblock>
</GRID>


Two Methods of adding a hidden file:

// textblock navigation time
         private void Navigation_ManipulationStarted (object sender, ManipulationStartedEventArgs e)
         {
             // The two methods achieve the same effect, but the principle is different-knowledge point ④
             this.NavigationService.Navigate (new Uri ("/ MainPage.xaml", UriKind.Relative));
             //this.NavigationService.GoBack ();
             e.Complete ();
             e.Handled = true;
         }

         protected override void OnManipulationStarted (ManipulationStartedEventArgs e)
         {
             // Solid color
             SolidColorBrush scb = new SolidColorBrush ();
             // alpha
             Color color = new Color ();
             color.A = (byte) 255;
             color.R = (byte) 145;
             color.G = (byte) 35;
             color.B = (byte) 15;
             scb.Color = color;

             ContentPanel.Background = scb;
             base.OnManipulationStarted (e);
         } 

Knowledge Point 4: Here, because there are only two pages, the results returned to the previous page are the same, but the principle is different, this. navigationservice. navigate is to implement a new URI instance, this. navigationservice. goback () is to move back to the latest page in the history. If there is no history page, exit the program;

 

Knowledge Point ⑤: Tombstone: Because Windows Phone does not support third-party background programs, it provides another method, tomstone. Simply put, when program A is still running, suddenly another program B, the system will temporarily close the thread of program a and temporarily store its State; when program B is used up, the thread of program a will restart and restore the state before program; in this section, the page navigation is a tombstone example.

Summary: The Core sentence of navigation is: this. navigationservice. navigate () and return to the previous page this. navigationservice. goback (), a simple understanding of the tombstone; find a method can also navigate to other pages as follows:

Uri uri = new uri ("/secondpage. XAML", urikind. Relative );
This. navigationservice. Source = URI;

 


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.