0

我的 windows phone 应用程序在加载主页时冻结。我在主构造函数上设置了断点,它会触发 OnNavigatedTo 事件,但不会触发“Loaded”事件。它通过构造函数中的 InitializeComponent()。它显示启动屏幕和主页应用程序栏,但此时冻结。

我最近重构了我的主命名空间,这导致主页无法加载。我通过启动对象修复了这个问题。

在重构之前,一切都在工作。

我应该包括什么代码?此时项目相当大,所以我不知道你真的希望我发布多少代码。

有任何想法吗??

4

2 回答 2

2

好的,我发现了问题。在 App.Xaml.cs 中,我犯了以下关键错误:

这是我的代码:

private void CompleteInitializePhoneApplication(object sender, NavigationEventArgs e)
    {
        // Set the root visual to allow the application to render
        if (RootVisual != null && RootVisual != RootFrame)
            RootVisual = RootFrame;

        // Remove this handler since it is no longer needed
        RootFrame.Navigated -= CompleteInitializePhoneApplication;
    }

这应该是:

    private void CompleteInitializePhoneApplication(object sender, NavigationEventArgs e)
    {
        // Set the root visual to allow the application to render
        if (RootVisual != RootFrame)
            RootVisual = RootFrame;

        // Remove this handler since it is no longer needed
        RootFrame.Navigated -= CompleteInitializePhoneApplication;
    }

Resharper 认为最好先检查 RootVisual 是否为空。令人难以置信的令人讨厌的错误,因为它只会挂在启动 PNG 并且永远不会加载,显然是因为没有设置 RootVisual。

于 2012-11-13T20:30:44.003 回答
0

我以前也遇到过这样的困难。听起来这可能是您的 XAML 中的一个问题,但实际上没有您的解决方案很难说。

您可以尝试以下几件事:

  • 检查所有静态/动态资源以确保它们仍然正确解析。
  • 检查您正在使用的任何绑定和绑定转换器是否仍在正确解析。特别是转换器,我过去曾遇到过他们的问题。

如果您遇到异常,但与代码中的特定点无关:

  • 尝试在您可能正在使用的任何或所有自定义属性上放置断点。默认情况下,调试器不会进入属性。我发现这是我自己的工作中出现许多异常的原因。

希望这可以帮助!

于 2012-11-13T00:26:20.317 回答