I am using the following code to start a WinUI3 App maximized:
public MainWindow()
{
this.InitializeComponent();
var windowHandle = WinRT.Interop.WindowNative.GetWindowHandle(this);
var windowId = Win32Interop.GetWindowIdFromWindow(windowHandle);
AppWindow appWindow = AppWindow.GetFromWindowId(windowId);
OverlappedPresenter presenter = (OverlappedPresenter)appWindow.Presenter;
presenter.Maximize();
Debug.WriteLine(presenter.State);
}
There are no errors, debug output reports the OverlappedPresenter state as Maximized, but the window stays in the restored state.
Any suggestions are welcome, thanks in advance.
CodePudding user response:
Try putting Maximize() in App's OnLaunched method:
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
...
presenter.Maximize();
}
Or the Window's OnActivated event:
private void OnActivated(object sender, WindowActivatedEventArgs args)
{
...
presenter.Maximize();
}