Mobile UWP中如何控制后向堆栈深度导航

Mobile UWP中如何控制后向堆栈深度导航,mobile,uwp,stack,back,depth,Mobile,Uwp,Stack,Back,Depth,如何控制UWP中的后堆栈深度导航?如何控制后堆栈深度我希望我的后堆栈只有3页。实际上,我希望后堆栈深度始终小于4。这是我的app.xaml.cs sealed partial class App : Application { /// <summary> /// Initializes the singleton application object. This is the first line of authored code /// executed

如何控制UWP中的后堆栈深度导航?如何控制后堆栈深度我希望我的后堆栈只有3页。实际上,我希望后堆栈深度始终小于4。

这是我的app.xaml.cs

 sealed partial class App : Application
{
    /// <summary>
    /// Initializes the singleton application object.  This is the first line of authored code
    /// executed, and as such is the logical equivalent of main() or WinMain().
    /// </summary>
    public App()
    {
        this.InitializeComponent();
        this.Suspending += OnSuspending;
    }

    /// <summary>
    /// Invoked when the application is launched normally by the end user.  Other entry points
    /// will be used such as when the application is launched to open a specific file.
    /// </summary>
    /// <param name="e">Details about the launch request and process.</param>
    protected override void OnLaunched(LaunchActivatedEventArgs e)
    {
        Frame rootFrame = Window.Current.Content as Frame;

        // Do not repeat app initialization when the Window already has content,
        // just ensure that the window is active
        if (rootFrame == null)
        {
            // Create a Frame to act as the navigation context and navigate to the first page
            rootFrame = new Frame();

            rootFrame.NavigationFailed += OnNavigationFailed;

            if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
            {
                //TODO: Load state from previously suspended application
            }

            // Place the frame in the current Window
            Window.Current.Content = rootFrame;

            SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested;

            SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility =
                rootFrame.CanGoBack ?
                AppViewBackButtonVisibility.Visible :
                AppViewBackButtonVisibility.Collapsed;
        }

        if (e.PrelaunchActivated == false)
        {
            if (rootFrame.Content == null)
            {
                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter
                rootFrame.Navigate(typeof(MainPage), e.Arguments);
            }
            // Ensure the current window is active
            Window.Current.Activate();
        }
    }

    /// <summary>
    /// Invoked when Navigation to a certain page fails
    /// </summary>
    /// <param name="sender">The Frame which failed navigation</param>
    /// <param name="e">Details about the navigation failure</param>
    void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
    {
        throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
    }

    /// <summary>
    /// Invoked when application execution is being suspended.  Application state is saved
    /// without knowing whether the application will be terminated or resumed with the contents
    /// of memory still intact.
    /// </summary>
    /// <param name="sender">The source of the suspend request.</param>
    /// <param name="e">Details about the suspend request.</param>
    private void OnSuspending(object sender, SuspendingEventArgs e)
    {
        var deferral = e.SuspendingOperation.GetDeferral();
        //TODO: Save application state and stop any background activity
        //save();
        deferral.Complete();
    }

    private void OnBackRequested(object sender, Windows.UI.Core.BackRequestedEventArgs e)
    {
        Frame rootFrame = Window.Current.Content as Frame;

        if (rootFrame.CanGoBack)
        {
            e.Handled = true;
            rootFrame.GoBack();
        }
    }
密封部分类应用程序:应用程序
{
/// 
///初始化singleton应用程序对象。这是编写代码的第一行
///已执行,因此是main()或WinMain()的逻辑等价物。
/// 
公共应用程序()
{
this.InitializeComponent();
这个.Suspending+=OnSuspending;
}
/// 
///当最终用户正常启动应用程序时调用。其他入口点
///将在启动应用程序以打开特定文件时使用。
/// 
///有关启动请求和过程的详细信息。
仅启动受保护的覆盖无效(启动ActivatedEventArgs e)
{
Frame rootFrame=Window.Current.Content作为Frame;
//当窗口已经有内容时,不要重复应用程序初始化,
//只需确保窗口处于活动状态
if(rootFrame==null)
{
//创建一个框架作为导航上下文并导航到第一页
rootFrame=新框架();
rootFrame.NavigationFailed+=OnNavigationFailed;
如果(例如,PreviousExecutionState==ApplicationExecutionState.Terminated)
{
//TODO:从先前挂起的应用程序加载状态
}
//将框架放置在当前窗口中
Window.Current.Content=rootFrame;
SystemNavigationManager.GetForCurrentView().BackRequested+=OnBackRequested;
SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility=
根框,坎戈巴克?
AppViewBackButtonVisibility。可见:
AppViewBackButtonVisibility.已折叠;
}
如果(如预启动激活==错误)
{
if(rootFrame.Content==null)
{
//导航堆栈未还原时,请导航到第一页,
//通过将所需信息作为导航传递来配置新页面
//参数
导航(typeof(MainPage),例如参数);
}
//确保当前窗口处于活动状态
Window.Current.Activate();
}
}
/// 
///当导航到某个页面失败时调用
/// 
///导航失败的帧
///有关导航失败的详细信息
void OnNavigationFailed(对象发送方,NavigationFailedEventArgs e)
{
抛出新异常(“加载页面失败”+e.SourcePageType.FullName);
}
/// 
///在挂起应用程序执行时调用。应用程序状态已保存
///不知道应用程序是否会随内容一起终止或恢复
///记忆仍然完好无损。
/// 
///挂起请求的源。
///有关暂停请求的详细信息。
暂停时的私有void(对象发送方,SuspendingEventArgs e)
{
var deleral=e.SuspendingOperation.getdeleral();
//TODO:保存应用程序状态并停止任何后台活动
//save();
延迟。完成();
}
OnBackRequested私有无效(对象发送方,Windows.UI.Core.BackRequestedEventArgs e)
{
Frame rootFrame=Window.Current.Content作为Frame;
if(根框架.CanGoBack)
{
e、 已处理=正确;
rootFrame.GoBack();
}
}

您可以在主页上堆叠,导航到主页并在其中写入代码。但我不知道您的代码,但如果您能阅读,我会用中文编写。您需要编辑您的问题,并在问题中包含代码,而不是在单独的答案中。