【问题标题】:Change default startup page for windows phone 8.1 app更改 windows phone 8.1 应用程序的默认启动页面
【发布时间】:2014-09-09 23:52:27
【问题描述】:

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

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

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

【问题讨论】:

    标签: c# wpf xaml visual-studio-2013 windows-phone-8.1


    【解决方案1】:

    试试这个

    WP 8.1 通用项目

    -> 添加新项目 -> 空白页
    -> 将其命名为 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>
    

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

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

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

    【讨论】:

    • Chubosaurus Software:这正是我一直在做的。但是 PivotPage 没有被识别为一种类型。编译器投诉:The type or namespace name 'PivotPage' could not be found (are you missing a using directive or an assembly reference?)
    • 啊,我想我知道你做错了什么。做构建 - >清洁解决方案。右键单击 WP8.1 项目 -> 将其设置为启动项目。右键单击 WP8.1 项目 -> 构建。不要做“构建解决方案”,只需构建该特定项目然后部署。发生这种情况是因为另一个项目也没有 PivotPage,因此要么将一个添加到另一个项目,要么使用一些#define。我将修改我的解决方案以向您展示我在说什么。
    • #if 指令完美运行。不必打扫。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多