问题描述
在我的应用程序的某些情况下,我必须取消后退导航.我是用代码做的:
In some case in my application, I have to cancel back navigation. I'm doing it with code:
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
if (e.NavigationMode == NavigationMode.Back)
{
if (WaitPanelGrid.Visibility == System.Windows.Visibility.Visible)
{
e.Cancel = true;
}
}
base.OnNavigatingFrom(e);
}
一切都好,除了一件事:在这个页面我有过渡:
And everything is OK, except one thing: In this page i have transitions:
<toolkit:TransitionService.NavigationInTransition>
<toolkit:NavigationInTransition>
<toolkit:NavigationInTransition.Backward>
<toolkit:TurnstileTransition Mode="BackwardIn" />
</toolkit:NavigationInTransition.Backward>
<toolkit:NavigationInTransition.Forward>
<toolkit:TurnstileTransition Mode="ForwardIn" />
</toolkit:NavigationInTransition.Forward>
</toolkit:NavigationInTransition>
</toolkit:TransitionService.NavigationInTransition>
<toolkit:TransitionService.NavigationOutTransition>
<toolkit:NavigationOutTransition>
<toolkit:NavigationOutTransition.Backward>
<toolkit:TurnstileTransition Mode="BackwardOut" />
</toolkit:NavigationOutTransition.Backward>
<toolkit:NavigationOutTransition.Forward>
<toolkit:TurnstileTransition Mode="ForwardOut" />
</toolkit:NavigationOutTransition.Forward>
</toolkit:NavigationOutTransition>
</toolkit:TransitionService.NavigationOutTransition>
并在 OnNavigatingFrom 中调用 Cancel 停止应用程序从导航返回,但过渡仍在工作,所以最后我只有黑屏,因为页面没有改变,但它被动画并移动到屏幕后面的某个地方.
And calling Cancel in OnNavigatingFrom stop application from navigate back, but transition is still working, so in the end i have just black screen, because page was not changed, but it was animated and moved somewhere behind screen.
我的问题是:如何取消导航和转换?
My question is: How I can cancel navigating AND transition?
推荐答案
摘自 这篇文章
如果您想禁用页面的导航转换,请在页面上将 TransitionService.NavigationInTransition 和 TransitionService.NavigationOutTransition 设置为 null.如果您想恢复这些值,只需预先存储它们,然后再次设置它们.
If you want to disable navigation transitions for a Page, set TransitionService.NavigationInTransition and TransitionService.NavigationOutTransition to null on the Page. If you want to restore those values, just store them beforehand and then set them again.
PhoneApplicationFrame frame = (PhoneApplicationFrame)Application.Current.RootVisual;
PhoneApplicationPage page = (PhoneApplicationPage)frame.Content;
// Save the transitions
NavigationInTransition oldIn = TransitionService.GetNavigationInTransition(page);
NavigationOutTransition oldOut = TransitionService.GetNavigationOutTransition(page);
// Clear the transitions
TransitionService.SetNavigationInTransition(page, null);
TransitionService.SetNavigationOutTransition(page, null);
// Restore the transitions
TransitionService.SetNavigationInTransition(page, oldIn);
TransitionService.SetNavigationOutTransition(page, oldOut);
这篇关于在 OnNavigatingFrom 上取消导航时停止 wp7 的过渡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!