How to fix AppWindow.TitleBar.SetDragRectangles not working in Windows App SDK 1.4.230822000?

Starcloudsea 60 Reputation points
2023-09-08T03:59:06.27+00:00

As shown in the image, I wrote these codes, which contain AppWindow.TitleBar.SetDragRectangles, and I'm sure that this code is working correctly, but these codes are not doing what they are supposed to do.d10dc2ef7a9afd41a709e8c749506bab

Why is this? I would like an answer from Microsoft, please!

By the way, I've heard that this is also affected by the DPI of the screen, how can I avoid this problem?

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.
747 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,584 questions
Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
8,818 questions
{count} votes

Accepted answer
  1. Castorix31 82,846 Reputation points
    2023-09-12T10:34:40.0266667+00:00

    so now I'm starting to wonder if Microsoft introduced some way to replace this "deprecated" SetDragRectangles?

    It has been replaced by InputNonClientPointerSource

    I tested by updating MSDN sample and it seems to work (still on Windows 10 only)

     IntPtr hWndMain = WinRT.Interop.WindowNative.GetWindowHandle(this);
     Microsoft.UI.WindowId myWndId = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(hWndMain);
     var incps = InputNonClientPointerSource.GetForWindowId(myWndId);
     // In SetDragRegionForCustomTitleBar, same MSDN code with dragRectsList... dragRects
     incps.SetRegionRects(NonClientRegionKind.Caption, dragRects);
    
    2 people found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. Castorix31 82,846 Reputation points
    2023-09-08T06:24:01.6066667+00:00

    Where is the code with IsCustomizationSupported and ExtendsContentIntoTitleBar ?

    Like in MSDN sample : https://learn.microsoft.com/en-us/windows/apps/develop/title-bar?tabs=wasdk#interactive-content


  2. Xiaopo Yang - MSFT 12,151 Reputation points Microsoft Vendor
    2023-09-12T02:08:47.2633333+00:00

    What @Castorix31 suspects is reasonable.

    Call SetDragRectangles only after you check IsCustomizationSupported and ExtendsContentIntoTitleBar to confirm that a custom title bar is supported and being used.

    Change to

                m_appWindow.TitleBar.ExtendsContentIntoTitleBar = true;
                //Set the window drag area
                if (AppWindowTitleBar.IsCustomizationSupported() && m_appWindow.TitleBar.ExtendsContentIntoTitleBar)
                    m_appWindow.TitleBar.SetDragRectangles(new RectInt32[]{new RectInt32(800, 0, ScreenWidth - 80, 40)});
    

    GIF 9-12-2023 10-00-07 AM