Change default startup page for windows phone 8.1 app

谁说我不能喝 提交于 2019-12-12 07:56:48

问题


I created a new Basic Page called PivotPage.xaml in the Windows Phone 8.1 project of the universal app solution. When I go to App.xaml under the Shared partition, I want to change HubPage in the code below to the newly created PivotPage. But VS refuses to recognize PivotPage as a legitimate type. The namespace of both pages and the class definitions are exactly the same.

if (!rootFrame.Navigate(typeof(HubPage), e.Arguments))
{
    throw new Exception("Failed to create initial page");
}

If there is any other way to change the default page please let me know that too.


回答1:


Try this

WP 8.1 Universal Project

-> Add New Item -> Blank Page
-> Name it MyPivotPage.xaml


MyPivotPage.xaml

<Page
    x:Class="YOUR_NAMESPACE.MyPivotPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:YOUR_NAMESPACE"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

    <Grid>
        <Pivot Title="MY APPLICATION">
            <!--Pivot item one-->
            <PivotItem Header="item1">
                <Grid/>
            </PivotItem>

            <!--Pivot item two-->
            <PivotItem Header="item2">
                <Grid/>
            </PivotItem>
        </Pivot>
    </Grid>
</Page>

Change "YOUR_NAMESPACE" to your namespace :)

Then in App.xaml.cs

#if WINDOWS_PHONE_APP
if (!rootFrame.Navigate(typeof(MyPivotPage), e.Arguments))
{
    throw new Exception("Failed to create initial page");
}
#endif
#if WINDOWS_APP
if (!rootFrame.Navigate(typeof(MainPage), e.Arguments))
{
    throw new Exception("Failed to create initial page");
}       
#endif

Clean your solution
Set your WP 8.1 Universal as your default startup project
Deploy to your device



来源:https://stackoverflow.com/questions/25755258/change-default-startup-page-for-windows-phone-8-1-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!