Reputation: 4542
Here is typical App.xaml.cs code
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();
}
}
When rootFrame.Navigate(typeof(SignInPage), e.Arguments);
is called, SignInPage
is created. In SignInPage.xaml.cs
, there might be code like: this.Frame.Navigate(typeof(FramePage));
. Is the Frame
from this.Frame.
the same as rootFrame
? If it is, when and where does the Page
class get assigned the root frame from App.xaml.cs
?
Upvotes: 1
Views: 2511
Reputation: 10015
Yes this is the same Frame
object, as the Page
has a reference to the frame controlling it's content. In other words the Frame
that did the navigation to the page.
Frame
Gets the controlling Frame for the Page content.
Source: learn.microsoft.com
This property is automatically set on navigation and is first available in your Page
object in the OnNavigatedTo
method.
Upvotes: 3