Replace `Page` with `WinRTXamlToolkit.Controls.AlternativePage`

回眸只為那壹抹淺笑 提交于 2020-01-15 06:10:48

问题


I'm attempting to use Windows RT XAML Toolkit so that I can have access to the TreeView control. I've created a new BlankApp that contains a MainPage containing XAML similar to this:

<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>

I want to change this Page to an WinRTXamlToolkit.Controls.AlternativePage. I've modified the XAML to be:

<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>

And modified the MainPage class to extend WinRTXamlToolkit.Controls.AlternativePage rather than Page.

Now when I launch my app, It fails in the following statement:

        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");
            }
        }

I receive the "Failed to create initial page", but not more details.

So my questions would be: 1. How can I find out more details on why the Navigate call is failing? I tried adding rootFrame.NavigationFailed += rootFrame_NavigationFailed;, but the navigation failed event does not seem to be getting raised. 2. How can I properly use the WinRTXamlToolkit.Controls.AlternativePage page?


回答1:


Did you do the rest of the changes needed to use the alternative page?

Take a look at the sample code in the SDK. Specifically here:

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));
    }
}


来源:https://stackoverflow.com/questions/16131740/replace-page-with-winrtxamltoolkit-controls-alternativepage

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