[API Spec] TitleBar's Content Custom Drag Regions

Merged
VI
8mo ago
+309-0

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):