2017-05-01 19 views
0

下面是典型App.xaml.cs代碼UWP根幀與信息頁幀

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));Framethis.Frame.rootFrame相同嗎?如果是,Page類何時何地從App.xaml.cs分配了根幀?

回答

2

是的這是相同的Frame對象,因爲Page有控制它的內容的框架的引用。換句話說,導航到頁面的Frame

框架

獲取控制框架的頁面內容。

來源:docs.microsoft.com

此屬性會自動在導航設定,第一個可用在OnNavigatedTo方法你Page對象。