microsoft / WindowsAppSDK

The Windows App SDK empowers all Windows desktop apps with modern Windows UI, APIs, and platform features, including back-compat support, shipped via NuGet.
https://docs.microsoft.com/windows/apps/windows-app-sdk/
MIT License
3.85k stars 323 forks source link

TitleBar draggable area breaks when window is maximized #4632

Closed JLucasK closed 3 months ago

JLucasK commented 3 months ago

Describe the bug

Maximizing the window of an app that has had its draggable area dynamically calculated causes the draggable area to not behave as expected. In our experience, the draggable area seems to start starting at the starting point + half of the width, to beyond some point. Additionally, the minimize and maximize buttons remain operable, the close button is not clickable.

Steps to reproduce the bug

Code

Import this method

[DllImport("User32.dll")]
internal static extern int GetDpiForWindow(IntPtr hwnd);

Configure the TitleBar

var titleBar = AppWindow.TitleBar;
titleBar.ExtendsContentIntoTitleBar = true;
titleBar.PreferredHeightOption = TitleBarHeightOption.Tall;
titleBar.ButtonBackgroundColor = Colors.Transparent;
titleBar.ButtonInactiveBackgroundColor = Colors.Transparent;

At some point in the app (perhaps on window size change), run this code

var scale = GetDpiForWindow() / 96f;
var rect = new RectInt32((int)(DragStart * scale), 0, (int)((DragEnd - DragStart) * scale), (int)(48 * scale));
AppWindow?.TitleBar?.SetDragRectangles(new[] { rect });

where DragEnd and DragStart are defined as the starting and stopping points on the x-axis that the draggable area should start and stop.

Running

Run the app, and resize the window (or whatever should trigger this). The draggable area at the top of the window should work correctly. Now, maximize the window. The draggable area does not work as expected.

Expected behavior

The draggable area covers the expected, provided area when maximized.

Screenshots

No response

NuGet package version

Windows App SDK 1.5.5: 1.5.240627000

Packaging type

Packaged (MSIX)

Windows version

No response

IDE

Visual Studio 2022

Additional context

The behavior is exhibited in 1.5.5, I was able to reproduce the issue as well in 1.5.4.

codendone commented 3 months ago

Same issue as microsoft/microsoft-ui-xaml#9749. The fix for that was released yesterday.