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

Starcloudsea 40 Reputation points

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.
602 questions
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.
9,031 questions
Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
6,040 questions
{count} votes

Accepted answer
  1. Castorix31 77,506 Reputation points

    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.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Castorix31 77,506 Reputation points

    Where is the code with IsCustomizationSupported and ExtendsContentIntoTitleBar ?

    Like in MSDN sample :

  2. Xiaopo Yang - MSFT 8,976 Reputation points Microsoft Vendor

    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