在取消OnNavigatingFrom上的导航时停止wp7转换

时间:2013-01-28 14:36:24

标签: c# .net windows-phone-7 navigation transitions

在某些情况下,在我的应用程序中,我必须取消导航。我正在使用代码:

    protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
    {
        if (e.NavigationMode == NavigationMode.Back)
        {
            if (WaitPanelGrid.Visibility == System.Windows.Visibility.Visible)
            {
                e.Cancel = true;
            }
        }
        base.OnNavigatingFrom(e);
    }

一切都很好,除了一件事:在这个页面我有过渡:

<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中调用取消停止应用程序从导航返回,但转换仍然有效,所以最后我只有黑屏,因为页面没有更改,但它被动画并移动到屏幕后面的某处。

我的问题是:如何取消导航和过渡?

1 个答案:

答案 0 :(得分:1)

摘自this article

禁用导航过渡

如果要禁用页面的导航过渡,请在页面上将TransitionService.NavigationInTransition和TransitionService.NavigationOutTransition设置为null。如果要恢复这些值,只需预先存储它们,然后再次设置它们。

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);