Private Sub OnNavigationFailed(sender As Object, e As NavigationFailedEventArgs) RootFrame.Navigate(GetType(MainPage), e.Arguments) ' configuring the new page by passing required information as a navigation ' When the navigation stack isn't restored navigate to the first page, ' TODO: Load state from previously suspended application. If e.PreviousExecutionState = ApplicationExecutionState.Terminated Then ' Create a Frame to act as the navigation context and navigate to the first page.ĪddHandler rootFrame.NavigationFailed, AddressOf OnNavigationFailed ' Do not repeat app initialization when the Window already has content, Protected Overrides Sub OnLaunched(e As LaunchActivatedEventArgs)ĭim rootFrame As Frame = Tr圜ast(, Frame) Throw ref new FailureException("Failed to load Page " + e->SourcePageType.Name) Void App::OnNavigationFailed(Platform::Object ^sender, Windows::UI::Xaml::Navigation::NavigationFailedEventArgs ^e) RootFrame->Navigate(TypeName(MainPage::typeid), e->Arguments) TODO: Restore the saved session state only when appropriate, scheduling the If (e->PreviousExecutionState = ApplicationExecutionState::Terminated) RootFrame->NavigationFailed += ref new Windows::UI::Xaml::Navigation::NavigationFailedEventHandler(this, &App::OnNavigationFailed) Void App::OnLaunched(LaunchActivatedEventArgs^ e)Īuto rootFrame = dynamic_cast(Window::Current->Content) Throw hresult_error(E_FAIL, hstring(L"Failed to load Page ") + e.SourcePageType().Name) Void App::OnNavigationFailed(IInspectable const&, NavigationFailedEventArgs const& e) RootFrame.Navigate(xaml_typename(), box_value(e.Arguments())) final launch steps after the restore is complete Restore the saved session state only when appropriate, scheduling the If (e.PreviousExecutionState() = ApplicationExecutionState::Terminated) Create a Frame to act as the navigation context and associate it with Void App::OnLaunched(LaunchActivatedEventArgs const& e)Īuto content = Window::Current().Content() Throw new Exception("Failed to load Page " + e.SourcePageType.FullName) Void OnNavigationFailed(object sender, NavigationFailedEventArgs e) RootFrame.Navigate(typeof(MainPage), e.Arguments)
configuring the new page by passing required information as a navigation When the navigation stack isn't restored navigate to the first page,
Place the frame in the current Window.
TODO: Load state from previously suspended application. If (e.PreviousExecutionState = ApplicationExecutionState.Terminated) RootFrame.NavigationFailed += OnNavigationFailed Create a Frame to act as the navigation context and navigate to the first page. just ensure that the window is active. Do not repeat app initialization when the Window already has content,
protected override void OnLaunched(LaunchActivatedEventArgs e)įrame rootFrame = as Frame
#Fram ramme code#
If not, this code sets the app window to a new Frame, then navigates the frame to the default initial page. If the app is resuming after being suspended, then the window might already be initialized. This code shows how an OnLaunched method override initializes the app window. The following code example is from the Blank App template in Microsoft Visual Studio. Get the WinUI 2 Gallery app (Microsoft Store).If you have the WinUI 2 Gallery app installed, open the app to see Page and Frame features in action. For more info, design guidance, and code examples, see the Navigation design basics overview.