BillJobs
BillJobs

Reputation: 43

How To Set Default Window Mode to Full Screen in WinUI 3?

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?

Upvotes: 3

Views: 2518

Answers (1)

Andrew KeepCoding
Andrew KeepCoding

Reputation: 13666

No. Don't call SwitchPresenter_FullScreen(docs) 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
}

Upvotes: 6

Related Questions