【问题标题】:Replace `Page` with `WinRTXamlToolkit.Controls.AlternativePage`将 `Page` 替换为 `WinRTXamlToolkit.Controls.AlternativePage`
【发布时间】:2013-04-21 13:40:20
【问题描述】:

我正在尝试使用Windows RT XAML Toolkit,以便可以访问TreeView 控件。我创建了一个新的 BlankApp,其中包含一个包含 XAML 的 MainPage,类似于:

<Page
    x:Class="BlankApp.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:BlankApp"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">

    </Grid>
</Page>

我想将此Page 更改为WinRTXamlToolkit.Controls.AlternativePage。我已将 XAML 修改为:

<xc:AlternativePage
    x:Class="BlankApp.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:xc="using:WinRTXamlToolkit.Controls"
    xmlns:local="using:BlankApp"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">

    </Grid>
</xc:AlternativePage>

并修改 MainPage 类以扩展 WinRTXamlToolkit.Controls.AlternativePage 而不是 Page

现在当我启动我的应用程序时,它在以下语句中失败:

        if (rootFrame.Content == null)
        {
            // When the navigation stack isn't restored navigate to the first page,
            // configuring the new page by passing required information as a navigation
            // parameter
            if (!rootFrame.Navigate(typeof(MainPage), args.Arguments))
            {
                throw new Exception("Failed to create initial page");
            }
        }

我收到“无法创建初始页面”,但没有更多详细信息。

所以我的问题是: 1. 我怎样才能找到更多关于Navigate 呼叫失败的详细信息?我尝试添加rootFrame.NavigationFailed += rootFrame_NavigationFailed;,但似乎没有引发导航失败事件。 2、如何正确使用WinRTXamlToolkit.Controls.AlternativePage页面?

【问题讨论】:

  • 在异常对话框中(如果使用 C# 方案,则为 Ctrl-alt-E),选择中断任何异常。发布您在那里看到的调用堆栈。
  • @ShaharPrish 我已将其设置为在所有异常情况下中断。在throw new Exception("Failed to create initial page"); 之前什么都不会被抛出,这就是为什么我很难弄清楚发生了什么。
  • 请注意,Windows 运行时(“WinRT”)与 Windows RT 相同。前者是开发架构,后者是平板电脑上的Windows 8。
  • @Zenox:你是对的。我应该更仔细地阅读代码。
  • 请注意,您不需要 AlternativeFrame 或 AlternativePage 即可使用 Treeview。这些用于页面转换和预加载支持。

标签: c# xaml windows-runtime winrt-xaml


【解决方案1】:

您是否完成了使用替代页面所需的其余更改?

查看 SDK 中的示例代码。具体在这里:

http://winrtxamltoolkit.codeplex.com/SourceControl/changeset/view/379f4af0e5862131aea1992f6875180abeddbcb6#WinRTXamlToolkit.Sample/AppShell.xaml.cs

public sealed partial class AppShell : UserControl
{
    public static AlternativeFrame Frame { get; private set; }

    public AppShell()
    {
        this.InitializeComponent();
        Frame = this.RootFrame;
        this.RootFrame.Navigate(typeof (MainPage));
    }
}

【讨论】:

  • 当然没有!当我查看我需要的更改时,我完全错过了这些。一旦我将 AppShell 安装到位,它就可以工作了。谢谢!
猜你喜欢
  • 2017-05-17
  • 1970-01-01
  • 1970-01-01
  • 2015-08-19
  • 1970-01-01
  • 1970-01-01
  • 2018-06-04
  • 2015-01-14
  • 1970-01-01
相关资源
最近更新 更多