簡體   English   中英

UWP根框架與頁面框架

[英]UWP Root frame vs Page frame

這是典型的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 this.Frame. rootFrame嗎? 如果是的話,那么在何時何地從App.xaml.cs中為Page類分配根框架?

是的,這是同一個Frame對象,因為Page引用了控制其內容的框架。 換句話說,導航到頁面的Frame

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

資料來源: docs.microsoft.com

此屬性在導航時自動設置,並且首先在OnNavigatedTo方法的Page對象中OnNavigatedTo

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM