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

Rwagsu 80 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 development | Windows App SDK
Windows for business | Windows Client for IT Pros | User experience | Other
Developer technologies | C#
Developer technologies | 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.
{count} votes

Answer accepted by question author
  1. Castorix31 91,501 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 91,501 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,736 Reputation points Microsoft External Staff
    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


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.