我使用以下代码来启动 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);
}
Run Code Online (Sandbox Code Playgroud)
没有错误,调试输出将 OverlappedPresenter 状态报告为最大化,但窗口仍处于恢复状态。
欢迎任何建议,提前致谢。
尝试将 Maximize() 放入 App 的 OnLaunched 方法中:
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
...
presenter.Maximize();
}
Run Code Online (Sandbox Code Playgroud)
或者窗口的 OnActivated 事件:
private void OnActivated(object sender, WindowActivatedEventArgs args)
{
...
presenter.Maximize();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
947 次 |
| 最近记录: |