简体   繁体   中英

How To Set Default Window Mode to Full Screen in WinUI3?

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?

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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM