Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Window size not correctly applied #10204

Closed
char8t opened this issue Nov 26, 2024 · 5 comments
Closed

Window size not correctly applied #10204

char8t opened this issue Nov 26, 2024 · 5 comments
Labels
bug Something isn't working needs-triage Issue needs to be triaged by the area owners

Comments

@char8t
Copy link

char8t commented Nov 26, 2024

Describe the bug

When specifiying the Window size via AppWindow.Resize(new SizeInt32(800, 450)) the actual window size appears to be little bit smaller than what is requested:

Image

One Idea of @dotMorten was (dotMorten/WinUIEx#200) that setting the window dimension is "taking the drop shadow into account". Is that true? If so how to get a window of exactly the size specified?

dotMorten/WinUIEx#200

Steps to reproduce the bug

  1. Create WinUI3 app
  2. Specifiy window dimensions
  3. Measure real results

Expected behavior

The window size to be exact to the requested size minus border

Screenshots

No response

NuGet package version

WinUI 3 - Windows App SDK 1.6.3: 1.6.241114003

Windows version

Windows 11 (24H2): Build 26100

Additional context

No response

@char8t char8t added the bug Something isn't working label Nov 26, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the needs-triage Issue needs to be triaged by the area owners label Nov 26, 2024
@castorix
Copy link

castorix commented Nov 26, 2024

It is because of DWM
On Windows 10, If I add the difference from GetWindowRect - (DwmGetWindowAttribute and DWMWA_EXTENDED_FRAME_BOUNDS), I get the right size (got after the window has been displayed, not at beginning)
(I get 786 * 443 :
104-904 vs 111-897 => 2 * 7
104-554 vs 104-547 => 7
=> 786 + 14, 443 + 7 => 800, 450
(maybe there are other values than DWMWA_EXTENDED_FRAME_BOUNDS on Windows 11...)

@DarranRowe
Copy link

If you want the client area to be set to the size specified, remember that AppWindow has the ResizeClient member. This will set the client area to the size specified by taking the styles into account.

Since the screenshot of your code shows that you are using ExtendContentIntoTitleBar, then what you are measuring there is the client area. Resize sets the window size and ResizeClient sets the window size to give a specified client size.

@char8t
Copy link
Author

char8t commented Nov 28, 2024

Oh i didn't know about ResizeClient. It works as expected just one thing to note: When using ExtendContentIntoTitleBar = true the client area will become a little bit bigger then what is requested 800, 450 -> 800, 480. Is there a way to programmatically get the title bar height so i can account for the extra size when using ExtendContentIntoTitleBar?

@DarranRowe
Copy link

The implementation of the title bar customisation functionality is shared with AppWindow in current versions. This means that you should be able to go through AppWindow to get an AppWindowTitleBar instance. AppWindowTitleBar has a Height property which reports the height of the title bar.

@char8t
Copy link
Author

char8t commented Dec 2, 2024

Thank you. Using AppWindow.TitleBar.Height together with ResizeClient when using ExtendContentIntoTitleBar = true does the job

@char8t char8t closed this as completed Dec 2, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added needs-triage Issue needs to be triaged by the area owners and removed needs-triage Issue needs to be triaged by the area owners labels Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-triage Issue needs to be triaged by the area owners
Projects
None yet
Development

No branches or pull requests

3 participants