Skip to content

feat!: UserControl inherits from Control - #23566

Merged
Xiaoy312 merged 10 commits into
feature/breakingchangesfrom
dev/xygu/20260625/feat-usercontrol-reparent
Jul 1, 2026
Merged

Xiaoy312 merged 10 commits into
feature/breakingchangesfrom
dev/xygu/20260625/feat-usercontrol-reparent

Conversation

@Xiaoy312

@Xiaoy312 Xiaoy312 commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

GitHub Issue: closes unoplatform/uno-private#2054

Part of the breaking-changes rollup epic #8339 (item BC14).

PR Type:

✨ Feature (breaking change — see migration note below)

What changed? 🚀

Reparents UserControl from ContentControl directly onto Control, matching the WinUI hierarchy Control → UserControl → Page. Uno previously inserted an extra ContentControl layer (Control → ContentControl → UserControl → Page).

  • UserControl : Control with its own UIElement-typed Content ([GeneratedDependencyProperty], AffectsMeasure | ValueDoesNotInheritDataContext). Single-child hosting is done directly via AddChild/RemoveChild in OnContentChanged — no ContentPresenter/ContentTemplate plumbing. Control's existing single-child layout (FindFirstChild/ArrangeFirstChild) handles measure/arrange, so UserControl adds no layout overrides and no per-platform partial.
  • Page inherits the new base unchanged; its OnBackgroundChanged override still works.
  • Consumer adaptation (minimal): IFrameworkElement.FindName gained a UserControl.Content branch (covers Page); hot reload's SwapViews gained a UserControl parent path. Other is ContentControl sites correctly stop matching UserControl/Page (the WinUI-aligned behavior) and needed no change.
  • The generated UserControl/Page stubs already matched the target shape, so no regeneration was required.

Benefits: true WinUI parity for the most-subclassed control, lighter/faster visual trees (a ContentPresenter/template layer dropped from every UserControl and Page), and Content correctly typed UIElement.

Validation

  • New Given_UserControl runtime tests (hierarchy, UIElement Content, ContentPresenter-less single-child rendering, reassignment/removal, DataContext-through-tree).
  • Skia Desktop: Given_UserControl 5/5; regression batch across Given_Control/Given_ContentControl (incl. FindName)/Given_ContentPresenter/Given_Frame (navigation)/Given_VisualStateManager/Given_FocusManager/Given_FrameworkElement = 407 passed / 0 failed.
  • WASM (Skia head): Given_UserControl 5/5 (assertion relaxed for the WASM fractional-DPI device-pixel grid).
  • Native WinUI (WinAppSDK): Given_UserControl 5/5 — confirms parity with the reference implementation.
  • Local visual sweep (light + dark) of UserControl/Page content hosting — background/border/padding/centered content render correctly; theming cascades through the directly-hosted child.

PR Checklist ✅

  • 🧪 Added Runtime tests (Given_UserControl), validated on Skia Desktop, WASM, and native WinUI
  • 📚 Impact spec reconciled (specs/050-breaking-changes-rollup/bc14-usercontrol-to-control.md)
  • 🖼️ Validated PR Screenshots Compare Test Run results (to review once CI runs)
  • ❗ Contains NO breaking changes — this PR is intentionally breaking (see below)
  • 👀 Reviewed 2 other open pull requests

Breaking change — impact & migration

UserControl and Page no longer inherit ContentControl:

  • ContentTemplate, ContentTemplateSelector, ContentTransitions, and the object-typed Content setter are removed from UserControl/Page. Content is now typed UIElement (matching WinUI). Code/XAML setting those members on a UserControl/Page must be updated.
  • x is ContentControl / ContentControl-typed casts against a UserControl/Page now evaluate false. Code relying on this must target Control/UserControl (or the concrete type) instead.

This matches WinUI exactly, so apps already written against the WinUI surface are unaffected. Ships last in its own stabilized PR per the epic plan; never batched.

@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 219945 has failed on Uno.UI - CI.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR aligns Uno’s UserControl inheritance with WinUI by reparenting it from ContentControl to Control, and reintroducing UserControl.Content as a UIElement-typed dependency property with direct single-child hosting. It also updates name lookup and hot-reload view swapping to account for the new hierarchy, adds runtime tests, and records the decision/implementation details in the breaking-changes spec.

Changes:

  • Reparent Microsoft.UI.Xaml.Controls.UserControl to inherit from Control and host content via AddChild/RemoveChild.
  • Update IFrameworkElement.FindName and hot reload SwapViews to handle UserControl.Content.
  • Add Given_UserControl runtime tests and reconcile the BC14 spec.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/Uno.UI/UI/Xaml/IFrameworkElement.cs Extends FindName search to include UserControl.Content when appropriate.
src/Uno.UI/UI/Xaml/Controls/UserControl/UserControl.Properties.cs Introduces a UIElement-typed Content DP for UserControl.
src/Uno.UI/UI/Xaml/Controls/UserControl/UserControl.cs Reparents UserControl to Control and swaps content via visual child add/remove.
src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_UserControl.cs Adds runtime coverage for hierarchy and content hosting behavior.
src/Uno.UI.RemoteControl/HotReload/ClientHotReloadProcessor.Common.cs Updates hot reload swapping to support UserControl as a parent.
specs/050-breaking-changes-rollup/bc14-usercontrol-to-control.md Documents the resolved decision and implementation/validation notes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions github-actions Bot added area/code-generation Categorizes an issue or PR as relevant to code generation area/automation Categorizes an issue or PR as relevant to project automation labels Jun 29, 2026
@unodevops

Copy link
Copy Markdown
Contributor

1 similar comment
@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 220140 has failed on Uno.UI - CI.

@Xiaoy312
Xiaoy312 force-pushed the dev/xygu/20260625/feat-usercontrol-reparent branch 2 times, most recently from 0f24b56 to e523ee1 Compare June 30, 2026 19:57
@Xiaoy312
Xiaoy312 enabled auto-merge June 30, 2026 20:07
@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 220317 did not find any UI Test snapshots differences.

@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 220317 has failed on Uno.UI - CI.

Xiaoy312 and others added 10 commits June 30, 2026 18:13
Reparent UserControl from ContentControl directly onto Control to match
the WinUI hierarchy (Control -> UserControl -> Page). UserControl now
declares its own UIElement-typed Content and hosts a single visual child
directly via AddChild/RemoveChild, dropping the ContentPresenter/template
layer. Control's existing single-child layout handles measure/arrange.

BREAKING CHANGE: UserControl and Page no longer inherit ContentControl.
ContentTemplate, ContentTemplateSelector, ContentTransitions and the
object-typed Content setter are removed; Content is now typed UIElement.
'x is ContentControl' against a UserControl/Page now returns false.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
FindName now descends into UserControl.Content (covers Page), since
UserControl no longer matches the ContentControl branch. Hot reload's
SwapViews gains a UserControl parent path so a UserControl-hosted child
is swapped correctly.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Cover the WinUI-aligned hierarchy, UIElement-typed Content, ContentPresenter-less
single-child rendering, content reassignment/removal, and DataContext flow
through the visual tree.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Resolve the open decision (commit to WinUI parity), record the as-landed
approach (AddChild/RemoveChild hosting, generated Content DP, no stub
regeneration), note BC14 is independent of BC38, and capture validation
status (Skia runtime done; parity/visual/WASM/hot-reload pending).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
When_Content_Set asserted exact ActualWidth/Height; the WASM browser head
rounds to a fractional-DPI device-pixel grid (50 -> 49.6), same artifact that
affects the FrameworkElement clip/arrange tests. Assert within 1px tolerance
to keep the intent (child laid out via Control's single-child layout) robust
across heads.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Declare [ContentProperty(Name = nameof(Content))] on the hand-written
UserControl partial and drop it from the generated partial, matching the
ContentControl/Border convention. ContentPropertyAttribute is
AllowMultiple = false, so keeping it on both partials would be a CS0579
duplicate-attribute error.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
When_Color_Thickness_GridLength_As_String loads a UserControl-rooted
XAML and cast the result to ContentControl. Since UserControl no longer
inherits ContentControl, the cast yields null and the test NRE'd.
UserControl exposes Resources (FrameworkElement) and Content, so the
assertions resolve unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The nested-DataTemplate hot-reload fixtures host a plain MyControl as a
Page's content. Page.Content (via UserControl) is now UIElement-typed
instead of object, so the generated `base.Content = new MyControl()`
no longer compiled (CS0029). Deriving MyControl from Control keeps it
assignable while preserving its [ContentProperty] DataTemplate slots.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
A sample whose IWaitableSample.SamplePreparedTask never completes
would block the entire auto-screenshot walk until the CI job timeout
(observed on ImageBrush_StreamSource). Cap the wait at 30s and log the
offending sample so a single stuck sample yields one bad screenshot
instead of hanging the whole job.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Assigning an already-decoded BitmapImage to MySource can raise
ImageOpened/ImageFailed synchronously via x:Bind, so subscribing after
the assignment missed those events, leaving _tcs incomplete and hanging
the snapshot run on this IWaitableSample.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@Xiaoy312
Xiaoy312 force-pushed the dev/xygu/20260625/feat-usercontrol-reparent branch from e523ee1 to b8552a2 Compare June 30, 2026 22:13
@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 220331 did not find any UI Test snapshots differences.

@Xiaoy312
Xiaoy312 merged commit 08e8238 into feature/breakingchanges Jul 1, 2026
68 checks passed
@Xiaoy312
Xiaoy312 deleted the dev/xygu/20260625/feat-usercontrol-reparent branch July 1, 2026 06:26
@github-actions github-actions Bot mentioned this pull request Jul 1, 2026
4 of 5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/automation Categorizes an issue or PR as relevant to project automation area/code-generation Categorizes an issue or PR as relevant to code generation kind/documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants