Home > Software engineering >  How To Set Default Window Mode to Full Screen in WinUI3?
How To Set Default Window Mode to Full Screen in WinUI3?

Time:08-07

namespace MyApp
    {
        public sealed partial class MainWindow : Window
        {
            AppWindow m_appWindow;
    
            public MainWindow()
            {
                this.InitializeComponent();
                m_appWindow = GetAppWindowForCurrentWindow();
            }
           
            private AppWindow GetAppWindowForCurrentWindow()
            {
                IntPtr hWnd = WinRT.Interop.WindowNative.GetWindowHandle(this);
                WindowId myWndId = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(hWnd);
                
                return AppWindow.GetFromWindowId(myWndId);
            }
            private void SwitchPresenter_FullScreen(object sender, RoutedEventArgs e)
            {
                m_appWindow.SetPresenter(AppWindowPresenterKind.FullScreen);
            }  
        }
    }

SwitchPresenter_FullScreen function is works but how can i set my app's default window mode to full screen? Can i call SwitchPresenter_FullScreen while app starting?

CodePudding user response:

No. Don't call SwitchPresenter_FullScreen directly. This method is for your UI controls (like CheckBox or ToggleButton).

Just add this line to your MainWindow constructor.

public MainWindow()
{
    this.InitializeComponent();
    m_appWindow = GetAppWindowForCurrentWindow();
    m_appWindow.SetPresenter(AppWindowPresenterKind.FullScreen);  // This line
}
  • Related