How to set the app window height and width on WinUI3?
Ijaz M
206
Reputation points
I wanted to set the width of the app to cover the available width of the display, and wanted to increase the apps height when a function was invoked.
Accepted answer
1 additional answer
Sort by: Most helpful
-
Albert Einstein 0 Reputation points
2024-10-31T03:21:51.54+00:00 using Microsoft.UI.Windowing; // Import this
IntPtr hwnd = WinRT.Interop.WindowNative.GetWindowHandle(this); // Assuming 'this' is your Window instance
var windowId = Win32Interop.GetWindowIdFromWindow(hwnd);
AppWindow appWindow = AppWindow.GetFromWindowId(windowId);
// Set the desired size using Resize()
appWindow.Resize(new SizeInt32(800, 600)); // Set width to 800 pixels and height to 600 pixels