How to set the app window height and width on WinUI3?

Ijaz M 206 Reputation points
2023-08-19T09:35:23.9333333+00:00

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.

Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
804 questions
{count} votes

1 additional answer

Sort by: Most helpful
  1. 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

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.