WindowsAppSDK: After setting `AppWindowTitleBar.ExtendsContentIntoTitleBar` on Windows 10, the title bar cannot drag (v1.2-preview1)

Describe the bug

This is a bug in WindowsAppSDK v1.2 preview1, when I set AppWindowTitleBar.ExtendsContentIntoTitleBar, the title bar can’t be dragged. In fact, this problem also happens when not using SetDragRectangles.

titleBar = appWindow.TitleBar;
titleBar.ExtendsContentIntoTitleBar = true;
titleBar.SetDragRectangles(new RectInt32[] { new RectInt32(0, 0, 10000, 48) });

https://user-images.githubusercontent.com/61003590/190835485-207620f4-b75c-45e2-a896-768e7cf28276.mp4

Steps to reproduce the bug

  1. Create new project
  2. Update package
  3. Write some code
  4. Run

Expected behavior

The title bar can be dragged.

Screenshots

No response

NuGet package version

1.2.220902.1-preview1

Packaging type

Packaged (MSIX)

Windows version

Windows 10 version 21H2 (19044, November 2021 Update)

IDE

Visual Studio 2022-preview

Additional context

<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.2.220902.1-preview1" />

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 31 (1 by maintainers)

Most upvoted comments

@Glitterinn I tested your workaround and it works fine. For others who don’t want read too much:

Simply add

SizeInt32 size = appWindow.ClientSize;
size.Height -= (int)(31 * User32.GetDpiForWindow(hwnd));
appWindow.ResizeClient(size);

after your appWindow.TitleBar.SetDragRectangles

* tips: appWindow & hwnd reprensents the same window here.

@onslauth Thanks for your answer, but that’s not what I want. I’m testing AppWindowTitleBar on Windows 10, this api was mentioned in v1.2 preview 1 release notes but it still doesn’t work.

I believe the issue you are having is because you have not called SetTitleBar after ExtendsContentIntoTitleBar.

I have created a minimal example that you can find here: https://github.com/onslauth/TitleBarTestApp

If you run the application as is, you will see the title bar is discoloured, but you will be able to click and drag. image

You can fix that by commenting out the following code. But you will notice that the control added to ‘GridTitleBar’ is no longer visible in the top left: App.xaml:

<!-- <SolidColorBrush x:Key="WindowCaptionBackground">Orange</SolidColorBrush> -->

image

You can solve that problem, by setting the WindowCaptionBackground colour to Transparent as follows:

<SolidColorBrush x:Key="WindowCaptionBackground">Transparent</SolidColorBrush>

Now the controls in GridTitleBar are visible and the title bar has the same colour as the rest of the application. image

At this point you can customise the title bar by adding controls to GridTitleBar in MainWindow.xaml. Here is a Youtube video that provides a good example: https://www.youtube.com/watch?v=rhYdNuBkqtE

After this, you might run into some issues that I am experiencing and for which I have opened a ticket: https://github.com/microsoft/WindowsAppSDK/issues/2987

Hope that helps.

this should be fixed now with 1.3 and 1.4. The comments above are also pointing to multiple right solutions. If it is an app which has been ported to newer winappsdk, it requires a app.manifest with compatibility check. You can refer to a new hello world winui3 app created by Visual Studio for the compatibility code, which can be copy pasted.

Second, AppWindowTitleBar.ExtendsContentIntoTitleBar provides a default custom titlebar which extends for entire width of the window (even without calling SetDragRectangle) .

Third, it is easy to get dimensions wrong. SetDragRectangle uses a non-dpi client coordinate.

I hope these points help. Given so much discussion has already happened on this issue and many of the things are stale, no longer applicable with new winappsdk release, I will close this issue. I encourage you to create a fresh issue if it continues to cause same issue, reference this issue but provide fresh response, post upgrade.

Well, I finally got around to testing a sample on Windows 10. It drags properly and double clicking on the title bar causes it to maximise and restore properly. In fact, the Windows 11 code is what worked without issue on Windows 10.

WindowTest2.zip

This is the Windows API project that I used to do this. As a note, it is still set to self contained, but that shouldn’t make a difference, the system that I was testing this on didn’t have 1.2 preview 1 installed on it. If you want to be sure, just remove the WindowsAppSDKSelfContained element from the .vcxproj file.

@tranhuynhthaitrung AppWindowTitleBar.PreferredHeightOption allows you to extend it. But to be honest, the Windows design guidelines state that title bars should either be 32 or 48 pixels. This class seems to conform to that. If you are looking for a general purpose API, your best option is still using DWM.

@castorix The release notes for 1.2 preview 1 states that full customisation is available on Windows 10.