0

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

    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 中调用 Cancel 停止应用程序从导航返回,但转换仍在工作,所以最后我只有黑屏,因为页面没有改变,但它被动画并移动到屏幕后面的某个地方。

我的问题是:如何取消导航和转换?

4

1 回答 1

1

摘自这篇文章

禁用导航转换

如果要禁用页面的导航转换,请在页面上将 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);
于 2013-01-28T15:27:05.400 回答