从墓碑返回时 RootVisual 为空?
您好,我刚刚发现我的应用程序在从逻辑删除返回时崩溃了。我能够在页面的构造函数中找到问题所在:
RadPhoneApplicationFrame frame = App.Current.RootVisual as RadPhoneApplicationFrame;
frame.PageTransitionCompleted +=
new EventHandler<EventArgs>(frame_PageTransitionCompleted);
每次重新激活应用程序时,RootVisual 都会将框架设置为空。我想知道这里是否存在转换问题,因为在使用此代码之前,我的逻辑删除工作正常,并且我能够在整个应用程序中自由导航。关于可能导致这种情况的原因有什么想法吗?或者也许有一个变通办法?
Hi I just found out that my application was crashing when returning from tombstoning. I was able to target the problem here inside the constructor of my page:
RadPhoneApplicationFrame frame = App.Current.RootVisual as RadPhoneApplicationFrame;
frame.PageTransitionCompleted +=
new EventHandler<EventArgs>(frame_PageTransitionCompleted);
Everytime the app is Re-Activated the RootVisual is setting the frame to null. I'm wondering if there is a casting issue here because before I used this code my tombstoning was working perfectly and I was able to navigate freely throughout the app. Any ideas on what might be causing this? Or maybe a work around?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该将此代码从页面构造函数移动到页面中的
OnNavieratedTo
方法重写中。原因是RootVisual
可能在RootFrame.Navierated
事件处理程序中设置,该事件处理程序是在页面构造之后生成的,而不是之前(这取决于您的App.xaml 中的实现) .cs
)。当然,由于
OnNavigateTo
方法可能会在一个页面上运行多次,因此您应该确保PageTransitionCompleted
事件处理程序没有分配两次(只需使用-=
在+=
之前)。另一种选择是将此代码移至
App.xaml.cs
。这对我来说最有意义,因为PageTransitionCompleted
事件与整个应用程序相关,而不是单个页面。You should move this code from page constructor to
OnNavigatedTo
method override in your page. Reason is thatRootVisual
is probably set inRootFrame.Navigated
event handler which is generated after page is constructed, not before (this depends of implementation in yourApp.xaml.cs
).Of course because
OnNavigatedTo
method may be runned more that once for a page, you should make sure thatPageTransitionCompleted
event handler is not assigned two times (just use-=
before+=
).Another option is to move this code to
App.xaml.cs
. This makes sense most to me, because thatPageTransitionCompleted
event is related to whole app, not a single page.