5
WinUI3修改默认窗口大小
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.
WinUI3修改默认窗口大小
2023-01-132023-01-20WinUI
WinUI3修改默认窗口大小
只需要在App.xaml.cs
的OnLaunched
下使用:
// 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
对象还有其他几个功能,如MoveAndResize
、Show
、Hide
和修改标题栏的功能。
最后吐槽一下Microsoft Doc是个什么垃圾玩意。
1、c# - WINUI 3.0 - Reunion 0.5 window size/// - Stack Overflow
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK