Skip to content

InputNonClientPointerSource.SetRegionRects seems to do not work when used with NonClientRegionKind.Maximize #10762

@SuGar0218

Description

@SuGar0218

Describe the bug

When ExtendsContentIntoTitleBar is true and an UIElement has been set as title bar by Window.SetTitleBar, use InputNonClientPointerSource.SetRegionRects with the region parameter is NonClientRegionKind.Maximize to set an area as maximize button area. When the pointer hovering on the maximize button area, the Snap Layout on Windows 11 does not appear.

Why is this important?

  • The built-in title bar acts not very similarly to native title bar on Windows 11: close button hovering background is dark red in native title bar on Windows 11 but is lighter red in WinUI 3, looking more like to UWP on Windows 10.
  • Some apps need custom title bar including caption buttons, so developers need to adapt the title bar to Windows 11 Snap Layout.

Steps to reproduce the bug

  1. Create a new WinUI 3 application project.
  2. Set ExtendsContentIntoTitleBar = true in MainWindow.
  3. When the root elements is Loaded, set title bar for MainWindow.
<?xml version="1.0" encoding="utf-8" ?>
<Window
    x:Class="InputNonClientPointerSourceIssue.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local="using:InputNonClientPointerSourceIssue"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    Title="InputNonClientPointerSourceIssue"
    mc:Ignorable="d">

    <Window.SystemBackdrop>
        <MicaBackdrop />
    </Window.SystemBackdrop>

    <Grid Loaded="Grid_Loaded">
        <Grid.RowDefinitions>
            <RowDefinition Height="auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <Rectangle
            x:Name="TitleBarDragArea"
            Height="30"
            Fill="{ThemeResource SystemAccentColor}" />
    </Grid>
</Window>
using Microsoft.UI.Input;
using Microsoft.UI.Xaml;

using Windows.Graphics;

namespace InputNonClientPointerSourceIssue;

public sealed partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        ExtendsContentIntoTitleBar = true;
    }

    private void Grid_Loaded(object sender, RoutedEventArgs e)
    {
        SetTitleBar(TitleBarDragArea);
        InputNonClientPointerSource
            .GetForWindowId(AppWindow.Id)
            .SetRegionRects(NonClientRegionKind.Maximize, [new RectInt32
            {
                X = 0,
                Y = 0,
                Width = (int) (30 * Content.XamlRoot.RasterizationScale),
                Height = (int) (30 * Content.XamlRoot.RasterizationScale)
            }]);
    }
}
  1. Hover the pointer on the left top rectagle area but there is no Snap Layout popup shows on Windows 11.

Actual behavior

Hover the pointer on the left top rectagle area that was set as NonClientRegionKind.Maximize region but there is no Snap Layout popup shows on Windows 11.

Expected behavior

When pointer hovering on the region that set as NonClientRegionKind.Maximize by InputNonClientPointerSource.SetRegionRects on Windows 11, the Snap Layout popup should appear.

Screenshots

The region on the top left is my NonClientRegionKind.Maximize region, but hovering pointer on it does not make Snap Layout popup appear like the actual maximize button.

Image

NuGet package version

WinUI 3 - Windows App SDK 1.7.3: 1.7.250606001

Windows version

Windows 11 (24H2): Build 26100

Additional context

I had tried to set my region NonClientRegionKind.Passthrough, the region cannot by drag as expected. It may ensure:

  • Setting NonClientRegionKind.Passthrough acts properly.
  • My area rect is passed to SetRegionRects correctly but it does not act properly.
private void Grid_Loaded(object sender, RoutedEventArgs e)
    {
        SetTitleBar(TitleBarDragArea);
        InputNonClientPointerSource
            .GetForWindowId(AppWindow.Id)
            .SetRegionRects(NonClientRegionKind.Passthrough, [new RectInt32
            {
                X = 0,
                Y = 0,
                Width = (int) (30 * Content.XamlRoot.RasterizationScale),
                Height = (int) (30 * Content.XamlRoot.RasterizationScale)
            }]);
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-TitleBarIssues related to custom window title bars.bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions