看起来像OnNavigatedTo事件和处理页面对象的错误 [英] Seems like a bug in the order of events OnNavigatedTo and disposing of a page object

查看:108
本文介绍了看起来像OnNavigatedTo事件和处理页面对象的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

   

   Hi,

   就像它说的主题它看起来像一个错误,但以防万一我想得到确认,或者可能有人建议解决方法。情况就是这样。在WMAppManifest中,我添加了像这样的协议扩展

   Like said it the topic it looks like a bug but just in case I'd like to get a confirmation or maybe somebody would suggest a workaround. The situation is this. In the WMAppManifest I add a protocol extension like this

    <Extensions>
      <Protocol Name="ftp" NavUriFragment="encodedLaunchUri=%s" TaskID="_default" />
    </Extensions>

   然后我添加一个处理ftp网址的UriMapper

   Then I add a UriMapper which handles ftp urls

            RootFrame.UriMapper = new UriMapper();

&NBSP;  这部分本身运作正常。当我点击时,让我们说在ftp链接上的一个Internet浏览器中,应用程序启动,NavigationContext充满了我的期望,然后我做我想做的事情。基本上,加载应用程序,
然后创建MainPage,然后调用OnNavigatedFrom,然后触发页面的Loaded事件。我对收到的ftp链路作出反应的主要逻辑是OnNavigatedFrom。我认为这是适合的地方。

   This part itself works fine. When I click, let's say in an internet explorer on an ftp link the application is started and NavigationContext is filled with what I expect and then I do what I want to do. Basically, the application is loaded, then the MainPage is created, then OnNavigatedFrom is called, then Loaded event for the page is fired. My main logic which reacts on the received ftp link is in the OnNavigatedFrom. I assume this is the right place for that.

   如果我先启动应用程序,然后转到Internet Explorer并单击ftp链接,则会出现问题。现在发生的是操作系统将应用程序移动到前台,然后调用OnNavigatedFrom,但是那样!主页
的未加载事件被触发(显然当前MainPage已被释放),然后创建新的MainPage并为该新页面触发Loaded事件。正如您在事件顺序中所看到的,我在OnNavigatedFrom中所做的一切都已消失,因为该页面已消失。

   The problem comes up if I start the application first, then go to Internet Explorer and click on an ftp link. What happens now is OS moves the application to foreground, then OnNavigatedFrom is called, BUT THEN!!! Unloaded event for the MainPage is fired (apparently current MainPage is disposed), then a new MainPage is created and Loaded event is fired for that new page. As you can see in this order of events everything I did in the OnNavigatedFrom is gone because that page is gone.

   对我来说,它看起来像一个bug。如果操作系统认为必须重新创建MainPage,则应首先重新创建它,然后在新创建的页面上调用OnNavigatedTo。我是对的吗?

   To me it looks like a bug. If OS thinks that the MainPage have to be recreated then it should recreate it first and then call OnNavigatedTo on that newly created page. Am I right?

   问候,

   Regards,

Alex

推荐答案

请做所有的这在App.xaml.cs中的Application Activated事件中导致焦点离开应用程序应用程序进入Deactivate模式,当焦点返回时它返回Activated。

Please do all of this in Application Activated event in App.xaml.cs cause whenever focus moves away from the application application goes into Deactivate mode and when focus return it returns to Activated.

希望这对你有所帮助。

Hope this will help you.

Muhammad Asad。

Muhammad Asad.


这篇关于看起来像OnNavigatedTo事件和处理页面对象的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆