Skip to content

[API Spec] TitleBar's Content Custom Drag Regions#10936

Merged
vinnarayana-msft merged 10 commits intomicrosoft:mainfrom
vinnarayana-msft:user/vinnarayana/titlebar-content-draggable/spec
Mar 25, 2026
Merged

[API Spec] TitleBar's Content Custom Drag Regions#10936
vinnarayana-msft merged 10 commits intomicrosoft:mainfrom
vinnarayana-msft:user/vinnarayana/titlebar-content-draggable/spec

Conversation

@vinnarayana-msft
Copy link
Copy Markdown
Contributor

@vinnarayana-msft vinnarayana-msft commented Dec 29, 2025

This PR introduces an API specification for improving TitleBar drag region handling. The proposal changes the default drag behavior to automatically exclude interactive controls, and adds TitleBar.IsDragRegion, AutoRefreshDragRegions, and RecomputeDragRegions() to give developers explicit control over which areas of TitleBar Content participate in window dragging.

Fixes

PR Type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

Description

Custom title bar layouts often combine interactive controls—like buttons and search boxes—with non‑interactive visual elements. When these elements are arranged using containers such as Grid, StackPanel, or nested layouts, the system cannot reliably determine which parts of TitleBar.Content should act as the draggable window surface. This can leave empty gaps and spacing areas unintentionally non‑draggable, resulting in inconsistent window movement.

This specification introduces two changes to address these issues:

Change 1: New default behavior

The framework now recursively walks the visual tree and automatically excludes only interactive controls from the drag region. Empty gaps and non‑interactive areas become draggable by default without any markup changes.

Change 2: Per‑element overrides and refresh control

A new set of APIs gives developers explicit control over drag region behavior:

  • TitleBar.IsDragRegion — A nullable boolean (IReference<Boolean>) attached property that lets developers explicitly mark elements as draggable (True), clickable (False), or framework‑decided (unset / null).
  • TitleBar.AutoRefreshDragRegions — When True, subscribes to LayoutUpdated events for continuous automatic drag region refresh. Default is False.
  • TitleBar.RecomputeDragRegions() — Manually triggers a full recomputation of drag regions after dynamic content changes.

This work is part of the improvements tracked in #10421.

Motivation and Context

Developers need a predictable way to control which parts of a custom title bar participate in window dragging. The TitleBar.IsDragRegion attached property lets developers override the framework's auto‑detection on any element, while the improved defaults ensure that interactive controls are automatically excluded and all other areas—including empty gaps and non‑interactive visuals—are draggable without additional markup. For dynamic scenarios, AutoRefreshDragRegions provides continuous automatic refresh, and RecomputeDragRegions() enables on‑demand refresh, giving developers full control over drag region behavior in any TitleBar layout.

How Has This Been Tested?

  • I have performed a self-review of my own code
  • I have added tests to cover my changes

Screenshots (if appropriate):

@microsoft-github-policy-service microsoft-github-policy-service Bot added the needs-triage Issue needs to be triaged by the area owners label Dec 29, 2025
@vinnarayana-msft
Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

@ghost1372
Copy link
Copy Markdown
Contributor

@vinnarayana-msft is there any plan to fix titlebar issues?
here you can find a list of titlebar issues:
microsoft/WindowsAppSDK#5250

@vinnarayana-msft vinnarayana-msft changed the title [API Spec] TitleBar's Content IsDraggable Property [API Spec] TitleBar's Content ExcludeFromDrag Property Dec 29, 2025
Copy link
Copy Markdown

@Zakariathr22 Zakariathr22 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest also using IsDragEnabled instead of ExcludeFromDrag because it avoids negative wording and follows common boolean naming rules.

@vinnarayana-msft
Copy link
Copy Markdown
Contributor Author

vinnarayana-msft commented Dec 31, 2025

I suggest also using IsDragEnabled instead of ExcludeFromDrag because it avoids negative wording and follows common boolean naming rules.

Thank you @Zakariathr22 for the suggestion. The intent behind using ExcludeFromDrag is that in custom TitleBar layouts, the entire content region effectively becomes draggable, and developers typically only need to mark interactive controls as not draggable. So the property acts as an opt‑out, not an opt‑in, which makes a negative‑form name more accurate for the underlying behavior.
That said, I’m open to considering alternative names that still convey this opt‑out pattern if there’s a clearer option.

@riverar
Copy link
Copy Markdown
Contributor

riverar commented Jan 5, 2026

Is there prior art for negative-form Boolean properties? I think it's more common to use positive Boolean properties. +1 to the suggested change here (from ExcludeFromDrag to IsDraggable or IsDragEnabled).

@riverar
Copy link
Copy Markdown
Contributor

riverar commented Jan 5, 2026

Microsoft Office allows dragging and Microsoft Teams does not. Which one is right?
image

image

Comment thread specs/TitleBar/titleBar-content-draggable-spec.md Outdated
Comment thread specs/TitleBar/titleBar-content-draggable-spec.md Outdated
@Jay-o-Way
Copy link
Copy Markdown
Contributor

Jay-o-Way commented Jan 8, 2026

So the property acts as an opt‑out, not an opt‑in

Irrelevant. It's a property, and if the default is true then so be it. A property should always have a neutral or positive phrasing.

Also, in my opinion, something like this should have been discussed and agreed upon, before opening a PR. Note that you are a Microsoft employee and therefore a professional level is inherently expected.

@vinnarayana-msft vinnarayana-msft changed the title [API Spec] TitleBar's Content ExcludeFromDrag Property [API Spec] TitleBar's Content Custom Drag Regions Jan 27, 2026
@pranav-gupta-msft
Copy link
Copy Markdown
Member

The PR Description, can also contain, "BugFix" as this is one of the pending bugs which we are fixing.

Comment thread specs/TitleBar/titleBar-content-draggable-spec.md
Comment thread specs/TitleBar/titleBar-content-draggable-spec.md Outdated
@Jay-o-Way
Copy link
Copy Markdown
Contributor

@pranav-gupta-msft how does a SPEC (documents for a new feature) fix an existing BUG? Those are two completely different things.

Comment thread specs/TitleBar/titleBar-content-draggable-spec.md Outdated
Comment thread specs/TitleBar/titleBar-content-draggable-spec.md Outdated
Comment thread specs/TitleBar/titleBar-content-draggable-spec.md Outdated
Comment thread specs/TitleBar/titleBar-content-draggable-spec.md
Comment thread specs/TitleBar/titleBar-content-draggable-spec.md Outdated
Comment thread specs/TitleBar/titleBar-content-draggable-spec.md Outdated
Comment thread specs/TitleBar/titleBar-content-draggable-spec.md
Comment thread specs/TitleBar/titleBar-content-draggable-spec.md Outdated
Comment thread specs/TitleBar/titleBar-content-draggable-spec.md Outdated
Comment thread specs/TitleBar/titleBar-content-draggable-spec.md Outdated
Comment thread specs/TitleBar/titleBar-content-draggable-spec.md Outdated
Comment thread specs/TitleBar/titleBar-content-draggable-spec.md Outdated
Comment thread specs/TitleBar/titleBar-content-draggable-spec.md Outdated
Comment thread specs/TitleBar/titleBar-content-draggable-spec.md
@vinnarayana-msft
Copy link
Copy Markdown
Contributor Author

Microsoft Office allows dragging and Microsoft Teams does not. Which one is right? image

image

This can be configured as per app requirements. With the new API's that we provide, the developer has the freedom to configure the behaviour that aligns with their requirements.

Comment thread specs/TitleBar/titleBar-content-draggable-spec.md Outdated
Comment thread specs/TitleBar/titleBar-content-draggable-spec.md Outdated
Comment thread specs/TitleBar/titleBar-content-draggable-spec.md Outdated
@vinnarayana-msft vinnarayana-msft merged commit 5f9e851 into microsoft:main Mar 25, 2026
1 of 2 checks passed
@vinnarayana-msft vinnarayana-msft deleted the user/vinnarayana/titlebar-content-draggable/spec branch March 25, 2026 08:24
This specification introduces **two changes** to address these issues:

1. **Changing the default behavior** for deciding which parts of the TitleBar can be used to drag. The framework now recursively walks the visual tree and automatically excludes interactive controls from the drag region, making empty gaps and non‑interactive areas draggable by default.
2. **Giving developers the ability to override the default behavior** on a per‑element basis using the `TitleBar.IsDragRegion` attached property, and control when drag regions are recomputed via `AutoRefreshDragRegions` and `RecomputeDragRegions()`.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the name be AutoRecomputeDragRegions to align with RecomputeDragRegions?


| Value | Meaning |
|---|---|
| **Not set** (`null`) | Framework decides: interactive controls are excluded from drag, non-interactive visuals are draggable. |
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this true? In the initial example, the outer Grid does not have the property set, and it is not interactive, so this statement says that the framework decides that it is draggable. Yet it has draggable children.

What is the rule if a parent and child disagree on draggability?

I think the rule is

  • If the property is set, then the value of the property is applied to the element and its children. The values on child elements are ignored.
  • If the property is not set, and the element is interactive, then the element and its children are excluded from drag. The values on child elements are ignored.
  • If the property is not set, and the element is not interactive, then the element is included in drag, but recursion continues into child elements to determine whether child elements are draggable or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-triage Issue needs to be triaged by the area owners

Projects

None yet

Development

Successfully merging this pull request may close these issues.