Change startup blank page

Pham Cuong 66 Reputation points
2021-12-27T07:30:03.313+00:00

How to start the app160607-aaa.png on startup to the user set screen instead of the ManinPage.xaml screen

Universal Windows Platform (UWP)
{count} votes

Accepted answer
  1. Roy Li - MSFT 32,236 Reputation points Microsoft Vendor
    2021-12-27T09:55:10.367+00:00

    Hello,

    Welcome to Microsoft Q&A!

    It looks like that that you just want to navigate to another page instead of the default MainPage. Here are the steps that you need to do:

    1) Go to the App.xaml.cs file.
    2) Find the OnLaunched event.
    3) Find this line of the code :

      rootFrame.Navigate(typeof(MainPage), e.Arguments);  
    

    4) Change the MainPage into the page that you want to show.
    5) Run your app again.

    Thank you.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


1 additional answer

Sort by: Most helpful
  1. Ken Tucker 5,846 Reputation points
    2021-12-27T09:55:33.277+00:00

    You can change the startup form in app.xaml.cs

        protected override void OnLaunched(LaunchActivatedEventArgs e)
        {
            Frame 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;
    
                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: Load state from previously suspended application
                }
    
                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }
    
            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(MainPage), e.Arguments);
                }
                // Ensure the current window is active
                Window.Current.Activate();
            }
        }
    

    just change MainPage to the page you want to start with. For example

      rootFrame.Navigate(typeof(PageAll), e.Arguments);
    
    0 comments No comments