wpf 更改 Windows Phone 8.1 应用程序的默认启动页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25755258/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 12:30:33  来源:igfitidea点击:

Change default startup page for windows phone 8.1 app

c#wpfxamlvisual-studio-2013windows-phone-8.1

提问by joym8

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.xamlunder the Shared partition, I want to change HubPage in the code below to the newly created PivotPage. But VS refuses to recognize PivotPageas a legitimate type. The namespace of both pages and the class definitions are exactly the same.

我在通用应用解决方案的 Windows Phone 8.1 项目中创建了一个名为 PivotPage.xaml 的新基本页面。当我转到共享分区下的App.xaml 时我想将下面代码中的 HubPage 更改为新创建的 PivotPage。但是 VS 拒绝识别PivotPage为合法类型。两个页面的命名空间和类定义完全相同。

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.

如果有任何其他方法可以更改默认页面,也请告诉我。

回答by Chubosaurus Software

Try this

尝试这个

WP 8.1 Universal Project

WP 8.1 通用项目

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

-> 添加新项目 -> 空白页
-> 将其命名为 MyPivotPage.xaml



MyPivotPage.xaml

我的数据透视页.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 :)

将“YOUR_NAMESPACE”更改为您的命名空间:)

Then in App.xaml.cs

然后在 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

清理您的解决方案
将您的 WP 8.1 Universal 设置为您的默认启动项目
部署到您的设备