How to switch "page" in Silverlight"

Source: Internet
Author: User

Recently, I was a beginner in Silverlight and had a lot of problems to solve. I wanted to translate all the good English versions here to help beginners who are not good at English (although I am not good at English). At the same time, the translation process is also a learning process. Time is tight. This time, we will record the method for switching the page.

This is the video "using multiple pages, Part 1" from "Jesse liberty". The basic method is to create a pageswticher. This pageswitcher does not directly display the page, but serves as a background, switches pages.

The specific method is:

Create a new usercontrol named pageswitcher. Remove the Grid Control in pageswitcher. XAML. The program is as follows:

< Usercontrol X: Class = "Silverlightdemo. pageswitcher"
Xmlns = "Http://schemas.microsoft.com/winfx/2006/xaml/presentation%22
Xmlns: x =" Http://schemas.microsoft.com/winfx/2006/xaml%22 >
</ Usercontrol >  

 

Then in the backgroundCodeAdd a method, for example, switchpage, to switch pages, and then call it in the constructor to display the first page to be displayed:

Public   Partial   Class Pageswitcher: usercontrol
{
Public Pageswitcher ()
{
Initializecomponent ();
Switchpage ( New Page ()); // Display the first page to be displayed
}

///   <Summary>
/// Switch page
///   </Summary>
///   <Param name = "Newpage"> Page to be switched </Param>
Public   Void Switchpage (usercontrol Newpage)
{
This . Content = Newpage;
}
}

 

Then, in the Event Response Method to switch pages on each page, you only need to do this:

Private   Void Btn_click ( Object Sender, routedeventargs E)
{
Pageswitcher switcher =   This . Parent As Pageswitcher;
Switcher. switchpage ( New Anotherpage ());
}

 

Finally, modify the application_startup method in APP. XAML. CS to modify the start page.

 

Private   Void Application_startup ( Object Sender, startupeventargs E)
{
This . Rootvisual =   New Pageswitcher ();
}

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.