Introduction to Navigation
Let’s see how navigation application Universal Windows Platform. First of all, it should be noted that the UWP application has only one window, which is represented by an object Window. The window contains a single frame, which occupies the entire space of the window. Represented by an object frame Frame. A frame already contains pages (represented class Page), which tend to occupy all the space of the frame. Thus, at a time we can see only one page. And as a rule, under the navigation technically refers to the transition from one page to another.
To use the navigation to create a new project. Let it be called NavigationApp. By default, a new standard project already contains navigation elements. If we look at the contents of the file App.xaml.cs i>, which we have in the default project and which stores application class, the method OnLaunched () we can see the following lines,
that is a Frame object is created first and placing it in the application window, and then proceed to the main page of the application, which is represented by MainPage class using the Navigate method ().
Although, in principle, we can dispense with the frame directly loading the page in a Window object, but the frame is easy to navigate, providing special techniques, as well as stores browsing history.
Now let us consider how we can make navigation between multiple pages. To do this, add a new page to the project by type Blank Page. We call it Page2,
To go to the next page used Frame.Navigate () method, which is transferred to the object type. In this case, we turn to the second page Page2.
Overload method Frame.Navigate () allows you to pass on passing an object. For example, give the line,
Now for the Page2 page. Any page that is any Page object has a number of methods that allow you to respond to events navigation,
OnNavigatedTo (NavigationEventArgs e), triggered when a transition to the current page
OnNavigatedFrom (NavigationEventArgs e), triggered by the completion of the transition from the current page
OnNavigatingFrom (NavigatingCancelEventArgs e), fires when the beginning of the transition from the current page
So, if we have to perform any actions during the transition to / from the page, we can override these methods. Since in this case, we are passing from the main page of a parameter, we can override OnNavigatedTo () method to get this option and something to do with it.
To do this, define the code XAML In Page2 text box to display the passed parameter,
that is e.Parameter object – this is the object that is passed as the second parameter of the method Frame.Navigate (typeof (Page2), the transition from the MainPage)
And the transition from the home page in Page2 Title Add a message transmitted from the MainPage,
We are not necessarily pass it a string. It can be an object of any class. For example, we have the following class PageInfo,