Windows Phone 7-dynamically changing the initial page of Windows Phone 7

Source: Internet
Author: User
The default page for Windows Phone 7 is configured in the wmappmanifest. xml file.
<Tasks>

<Defaulttask name = "_ default" navigationpage = "loginpage. XAML"/>

</Tasks>

If the initial Page is changed according to the status when the program is started, for example, when the program is started, it determines whether the user is logged on. If the program is not logged on, it will jump to loginpage. XAML; otherwise, it will jump to other interfaces.

The Code is as follows:
Private void initializephoneapplication ()
{
If (phoneapplicationinitialized)
{
Return;
}
// Create the frame but don't set it as rootvisual yet; this allows the splash
// Screen to remain active until the application is ready to render.
Rootframe = new phoneapplicationframe ();
Rootvisual = rootframe;
Rootframe. navigated + = completeinitializephoneapplication;
// Handle navigation failures
Rootframe. navigationfailed + = rootframe_navigationfailed;
Rootframe. Navigating + = new navigatingcanceleventhandler (rootframe_navigating); // Add the navigating event
// Ensure we don't initialize again
Phoneapplicationinitialized = true;
}
Void rootframe_navigating (Object sender, navigatingcanceleventargs E)
{
If (E. Uri. tostring (). Contains ("loginpage. XAML ")&&! Api. isverify) // The conditions must be met here, because rootframe uses navigating when navigate on any page, or uses the same recursive method as rootframe. navigated.
{
E. Cancel = true; // cancel the event
String uristring = "/loginpage. XAML ";
Uri ur = new uri (uristring, urikind. Relative );
This. rootframe. Dispatcher. begininvoke (delegate
{
This. rootframe. navigate (UR );
});
}
}

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.