看起来像OnNavigatedTo事件和处理页面对象的错误

编程入门 行业动态 更新时间:2024-10-25 15:27:07
本文介绍了看起来像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();

这部分本身运作正常。当我点击时,让我们说在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事件和处理页面对象的错误

本文发布于:2023-05-31 22:05:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/400238.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对象   错误   事件   页面   OnNavigatedTo

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!