【发布时间】: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