Skip to content

Instantly share code, notes, and snippets.

View marb2000's full-sized avatar
💭
I'm busy these days, I may be slow to respond.

Miguel Ramos marb2000

💭
I'm busy these days, I may be slow to respond.
View GitHub Profile
@marb2000
marb2000 / WinUI3
Last active July 4, 2022 13:10
Set Window size
public static class WindowExtensions
{
public static void SetSize(this Window window, int width, int height)
{
// To set the size you need to wrap the XAML window in AppWindow
var hwnd = WinRT.Interop.WindowNative.GetWindowHandle(window);
var windowsId = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(hwnd);
var appWindow = Microsoft.UI.Windowing.AppWindow.GetFromWindowId(windowsId);
// Notice that AppWindow uses raw pixels because it's a low level API.