[英]Window doesn't maximize in WinUI3
我正在使用以下代碼啟動最大化的 WinUI3 應用程序:
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);
}
沒有錯誤,調試 output 將 OverlappedPresenter state 報告為已最大化,但 window 仍保留在已恢復的 state 中。
歡迎任何建議,在此先感謝。
嘗試將 Maximize() 放在 App 的 OnLaunched 方法中:
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
...
presenter.Maximize();
}
或者 Window 的 OnActivated 事件:
private void OnActivated(object sender, WindowActivatedEventArgs args)
{
...
presenter.Maximize();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.