【问题标题】:UWP Root frame vs Page frameUWP 根框架与页面框架
【发布时间】:2017-05-01 14:48:02
【问题描述】:

这里是典型的 App.xaml.cs 代码

protected override void OnLaunched(LaunchActivatedEventArgs e)
    {
#if DEBUG
        if (System.Diagnostics.Debugger.IsAttached)
        {
            //this.DebugSettings.EnableFrameRateCounter = true;
        }
#endif
        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;
            rootFrame.Navigated += OnNavigated;

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

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

            // Register a handler for BackRequested events and set the
            // visibility of the Back button
            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(SignInPage), e.Arguments);
            }
            // Ensure the current window is active
            Window.Current.Activate();
        }
    }

rootFrame.Navigate(typeof(SignInPage), e.Arguments);被调用时,SignInPage被创建。在SignInPage.xaml.cs 中,可能有如下代码:this.Frame.Navigate(typeof(FramePage));。来自this.Frame.Frame 是否与rootFrame 相同?如果是,Page 类何时何地从App.xaml.cs 获得根框架?

【问题讨论】:

    标签: c# uwp uwp-xaml


    【解决方案1】:

    是的,这是同一个Frame 对象,因为Page 具有对控制其内容的框架的引用。换句话说,导航到页面的Frame

    框架

    获取页面内容的控制框架。

    来源:docs.microsoft.com

    此属性在导航时自动设置,并且首先在 OnNavigatedTo 方法中的 Page 对象中可用。

    【讨论】:

      猜你喜欢
      • 2023-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-17
      • 1970-01-01
      • 1970-01-01
      • 2020-08-06
      • 1970-01-01
      相关资源
      最近更新 更多