5

WinUI3修改默认窗口大小

 1 year ago
source link: https://direct5dom.github.io/2023/01/13/WinUI3%E4%BF%AE%E6%94%B9%E9%BB%98%E8%AE%A4%E7%AA%97%E5%8F%A3%E5%A4%A7%E5%B0%8F/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

WinUI3修改默认窗口大小

2023-01-132023-01-20WinUI

WinUI3修改默认窗口大小

只需要在App.xaml.csOnLaunched下使用:

// Use 'this' rather than 'window' as variable if this is about the current window.
IntPtr hWnd = WinRT.Interop.WindowNative.GetWindowHandle(window);
var windowId = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(hWnd);
var appWindow = Microsoft.UI.Windowing.AppWindow.GetFromWindowId(windowId);

然后即可对窗口默认大小进行设定:

appWindow.Resize(new Windows.Graphics.SizeInt32 { Width = 480, Height = 800 });

AppWindow对象还有其他几个功能,如MoveAndResizeShowHide和修改标题栏的功能。


最后吐槽一下Microsoft Doc是个什么垃圾玩意。

1、c# - WINUI 3.0 - Reunion 0.5 window size/// - Stack Overflow


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK