应用无法导航到MainPage

Rom*_*asz 3 c# windows-phone windows-runtime windows-phone-8.1

我在我的WP8.1 RT应用程序上遇到了一个奇怪的问题 - 我的一位测试人员报告称他在启动画面后看到了黑屏.该应用程序不会崩溃,挂起电话或其他 - 只是黑屏而不是MainPage.我在代码中实现了一些Trace方法来跟踪问题.代码如下所示:

// OnLaunched method that gets called when the App starts
protected async override void OnLaunched(LaunchActivatedEventArgs e)
{
    await Trace.WriteLineAsync(true, "Launched");
    Frame rootFrame = CreateRootFrame();
    await Trace.WriteLineAsync(true, "Before - better checkup");
    if (rootFrame.Content == null)
    {
        await Trace.WriteLineAsync(false, "Rootframe content was null, navigating");
        if (!rootFrame.Navigate(typeof(MainPage), e.Arguments))
            await Trace.WriteLineAsync(false, "Navigation false");
        else await Trace.WriteLineAsync(false, "Navigation was ok");
    }
    await Trace.WriteLineAsync(true, "After - better checkup");
    Window.Current.Activate();
} 

// Method creating the rootFrame:
private Frame CreateRootFrame()
{
    Trace.WriteLineAsync(true, "Create Root frame");
    Frame rootFrame = Window.Current.Content as Frame;
    if (rootFrame == null)
    {
        Trace.WriteLineAsync(true, "Root frame was null");
        rootFrame = new Frame();
        SuspensionManager.RegisterFrame(rootFrame, "AppFrame");
        rootFrame.NavigationFailed += OnNavigationFailed;
        Window.Current.Content = rootFrame;
        Trace.WriteLineAsync(false, "Window content {0}", Window.Current.Content.ToString());
    }
    return rootFrame;
}
Run Code Online (Sandbox Code Playgroud)

beta测试人员得到的日志如下所示:

2014-10-06 13:02:56: Launched
2014-10-06 13:02:56: Create Root frame
2014-10-06 13:02:56: Root frame was null
Window content Windows.UI.Xaml.Controls.Frame
2014-10-06 13:02:57: Before - better checkup
Rootframe content was null, navigating
Navigation false
2014-10-06 13:02:57: After - better checkup
2014-10-06 13:03:01: App.cs suspending event
Run Code Online (Sandbox Code Playgroud)

正如你所看到的那样,最重要的一行就是Navigation false这意味着

if (!rootFrame.Navigate(typeof(MainPage), e.Arguments))
     await Trace.WriteLineAsync(false, "Navigation false");
Run Code Online (Sandbox Code Playgroud)

导航返回false - 我无法在我的Frame中导航,没有崩溃,没有挂起 - (Suspending event works),只是无法访问MainPage.我完全不知道问题的根源是什么.此外 - 在我的手机上一切正常,其他设备也都可以 - 调试和发布.

有没有人知道为什么我无法导航到我的MainPage?

编辑 - 添加了导航失败事件:

void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
{
    Trace.WriteLineAsync(true, "Failed to load page");
    throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
}
Run Code Online (Sandbox Code Playgroud)

Rom*_*asz 5

感谢Nate Diamond的评论,我开始以不同的方式寻找问题的原因.我添加这个答案,因为它可能有一天帮助某人.

最后经过beta测试人员的多次尝试和帮助后发现问题是由在Page的构造函数之前初始化的变量之一引起的.初始化导致异常被Navigate方法吞噬,因此返回false.

另一件事是为什么初始化导致异常,但那是另一个故事.