Skip to content

refactor!: Remove the ContentPresenter bypass - #24187

Merged
MartinZikmund merged 8 commits into
feature/breakingchangesfrom
dev/xygu/20260824/remove-contentpresenter-bypass
Aug 25, 2026
Merged

MartinZikmund merged 8 commits into
feature/breakingchangesfrom
dev/xygu/20260824/remove-contentpresenter-bypass

Conversation

@Xiaoy312

@Xiaoy312 Xiaoy312 commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

GitHub Issue: internal — uno-private#2163 (the template allows "GitHub issue or internal"; there is no public issue for this). Note unoplatform/uno#2163 is an unrelated closed 2019 Calculator issue, so closes #2163 is deliberately not used here.

PR Type:

💬 Other... — breaking change: removes a Uno-only rendering shortcut and reduces public API surface on ContentControl. (🔄 Refactoring doesn't fit; there are API changes.)

What changed? 🚀

ContentControl carried a Uno-only shortcut — IsContentPresenterBypassEnabled — that skipped the ContentPresenter and parented Content (or the materialized ContentTemplate) directly, whenever the control had no Template and its default style declared no Template setter. Its own doc comment gave the reason: an Android 4.4 stack-depth workaround (32 KB stack, fixed by ART).

The bypass was already inert — this is mostly dead-code removal

The issue reads as a behavioural fix. It isn't, and that's worth stating up front so reviewers don't go looking for a rendering change.

The default ContentControl template in Generic.xaml is gated on a conditional-XAML prefix. At the time this work started that prefix was spelled netstdref:, which reads like "reference build only". It never meant that: _IsNetStdRef was true whenever UnoRuntimeIdentifier was Skia or WebAssembly, or the TFM was plain netX.0. Uno.UI.csproj sets UnoRuntimeIdentifier=Skia and targets Skia TFMs only — there is no native Android/iOS Uno.UI build any more — so the setter was always included, HasDefaultTemplate(typeof(ContentControl)) was always true, and IsContentPresenterBypassEnabled was always false for a bare ContentControl.

The netstdref / not_netstdref prefixes were retired from the whole repo on the base branch while this was in flight (the conditional-prefix cleanup). The setter now carries not_winappsdk:, which says what it means. For the Skia-only Uno.UI that is unconditionally included, so the conclusion is unchanged — only the misleading spelling is gone. This PR therefore makes no change to Generic.xaml.

An independent record of the same fact already lived in the test suite (Given_FrameworkTemplate.cs):

"Real Skia applies the default ContentControl ControlTemplate (a ContentPresenter), so the materialized ContentTemplate root lives on the inner ContentPresenter, not on ContentControl.ContentTemplateRoot (which stays null when a template is present)."

So padding, content alignment, the presenter layer and templatedParent on ContentTemplate roots are all unchanged — that was already the shipping behaviour.

Commits

  1. refactor!: Remove the ContentPresenter bypass — deletes IsContentPresenterBypassEnabled, UpdateContentTemplateRoot, SyncDataContext, the content-DataContext override plumbing, the ImplicitTextBlock placeholder path, and the OnLoaded/OnVisibilityChanged/OnDataContextChanged/MeasureOverride overrides that existed only to drive it. ContentControl.cs goes 538 → 180 lines. Also drops:
    • the memoized Type-keyed HasDefaultTemplate lookup and the ALC-teardown sweep that only existed to unpin it (a leak and its workaround, both gone);
    • ButtonBase.OnContentTemplateRootSet() => RegisterEvents() and the partial void RegisterEvents() it called — dead twice over, since the hook only fired under the bypass and the partial lost its last implementation when the native Android/iOS partials were dropped;
    • the (this as ContentControl)?.Content == GetFirstChild() clause and ClearContentPresenterBypass() escape hatch in FrameworkElement.ApplyTemplate, which collapses to !HasTemplateChild();
  2. chore: Register and document the bypass removal — PackageDiffIgnore entries, a migration note in migrating-to-uno-7.md, and the impact spec.
  3. refactor!: Report ContentTemplateRoot from ContentPresenter — see below.
  4. docs: Add #2163 to the breaking-changes rollup — checklist entry in specs/050-breaking-changes-rollup/spec.md.
  5. docs: Follow the conditional-prefix cleanup on the base — after merging the updated base, drops the now-redundant Generic.xaml edit and re-words the docs for the current prefix spelling.
  6. test: Read a presenter's template root from the tree — see "Collision with BC01" below.

Collision with BC01 (#24070)

BC01 landed on feature/breakingchanges while this was in flight and was merged in here. It adds two suites — TemplatedParentTests.Recycling and Given_FrameworkTemplate_And_Leak — that host a bare ContentPresenter (the only way to exercise the pooled-materialization path, since Control.Template is materialized uncached) and read its ContentTemplateRoot. This PR makes that property private, so the merge failed every Build Samples App job with the same three CS1061.

A standalone presenter has no ContentControl to report to, so those three sites now read the materialized root as the presenter's single visual child — the same pattern the Given_ContentControl tests in this PR already use. No production code changed.

ContentTemplateRoot: one accessor, on ContentControl

ContentTemplateRoot is genuine WinUI API on ContentControl and does not exist on WinUI's ContentPresenter. Evidence, all local:

  • the generated stub Generated/…/ContentControl.cs carries // Skipping already declared property ContentTemplateRoot and // Forced skipping of method …ContentControl.ContentTemplateRoot.get. These stubs are generated by walking the WinAppSDK reference metadata; a member absent from it produces no line at all;
  • only a .get is listed — WinUI's property is read-only, so dropping Uno's protected set from the public surface is parity, not just cleanup;
  • the generated ContentPresenter stub contains no ContentTemplateRoot line whatsoever.

Because the bypass never assigned it, ContentControl.ContentTemplateRoot returned null for every control. The templated ContentPresenter now reports its materialized root there — mirroring WinUI's CContentPresenter writing ContentControl::m_tpContentTemplateRoot — and the presenter's own property drops to private.

This supersedes BC36 (#16148), which deliberately chose internal over private "because in-assembly callers read it cross-type". Those callers only existed because the ContentControl accessor was always null; spec.md records the reversal.

Three MUX ports read the null value and degraded silently. Two are genuine fixes (SelectorItem's automation-name fallback, ItemsRepeaterScrollHost's TransformToVisual against the scroll viewer's content root); HyperlinkButton already worked via an explicit // TODO Uno: … which is null workaround and is rewritten onto the real accessor.

When a template hosts several presenters under one templated parent (ContentDialog's Title/Icon, CommandBar), the reporting one is picked by comparing the Content dependency-property values — the CLR properties can't be used, because ContentControl.Content's getter falls back to DataContext when the DP is unset.

Testing 🧪

  • Runtime (Skia Desktop): Given_ContentControl + Given_ContentPresenter + Given_Control → 301/301. Given_ItemsControl + Given_Button + Given_HyperlinkButton → 27/27, including When_HyperlinkButton_With_Implicit_Content_Should_Be_Underlined (covers the rewritten accessor) and the container-recycling tests.

  • Given_ContentDialog 17/19. The two failures (When_DefaultButton_Set / _Not_Set, foreground-colour asserts) are pre-existing — reproduced identically on a clean tree by stashing this branch and rebuilding.

  • Unit tests: 13 failures, all the pre-existing When_Calendar timezone set. Given_FrameworkTemplate's MaterializedRoot helper now reads ContentControl.ContentTemplateRoot directly and passes, which is runtime proof of both the report and the clear-on-teardown path.

  • New tests in Given_ContentControl: the presenter is materialized for a bare ContentControl; ContentTemplateRoot returns the presenter's root; it is cleared when ContentTemplate is removed.

  • Consumer build: SamplesApp.Skia.Generic builds clean (API reductions break at consumers, not definitions). Each commit verified to build standalone.

  • Re-validated after merging the updated base (feature/breakingchanges had moved ~20 commits, including the conditional-prefix cleanup): build clean, unit tests back to the same 13-failure baseline.

  • After the BC01 merge: Given_ContentControl + Given_FrameworkTemplate_And_Leak + TemplatedParentTests → 34/34, 3 skipped (BC01's own [Ignore]d recycling tests, Template recycling for reworked Templated-Parent system #18317). This matters beyond the compile fix: BC01 reworked the templated-parent mechanism this feature rides on, and ContentTemplateRoot is reported from inside the materialization path — the green run is what proves the report still fires.

  • ✅ WinAppSDK Sync Generator Check passed on CI, confirming that retiring the ContentTemplateRoot type carve-out in SymbolMatchingHelpers leaves src/Uno.UI/Generated/** byte-identical. (It could not be run locally — build/run-api-sync-tool.cmd dies on NETSDK1045 for net11.0 plus a missing tvos workload.)

PR Checklist ✅

Breaking changes — impact and migration

Targeting the 7.0 breaking-changes branch; registered in build/PackageDiffIgnore.xml and doc/articles/migrating-to-uno-7.md.

  1. Behavioural. A ContentControl subclass that sets its own DefaultStyleKey and provides no Template in its default style no longer renders Content — it renders nothing, as on WinUI. Migration: give it a default style with a Template, or leave DefaultStyleKey alone so it inherits the ContentControl default template. In-framework, only the unused DatePickerSelector / TimePickerSelector are in that shape. Default ContentControl usage is unaffected.
  2. API. ContentControl.ContentTemplateRoot loses its protected set (WinUI's property is get-only); UpdateContentTemplateRoot(), SyncDataContext() and the OnVisibilityChanged/OnDataContextChanged/MeasureOverride overrides are removed from ContentControl.
  3. Value change. ContentControl.ContentTemplateRoot goes from always-null to populated. Code that (deliberately or not) relied on the null will now see the template root.

Out of scope — follow-ups

  • The default style sets HorizontalContentAlignment="Left" / VerticalContentAlignment="Top" while BC45 moved Control's DP defaults to Center/Center. Both are live today and they disagree once the style applies — a pre-existing divergence. It needs a native-WinUI measurement and its own item; bundling a real visual change into a dead-code removal would be wrong.
  • ItemsControl.GetGroupHeaderContainer still returns a ContentControl where WinUI returns a ContentPresenter. Observable via ItemContainerStyle and ContainerFromItem casts — its own breaking-change item.
  • SymbolMatchingHelpers.ArePropertiesMatching has its IsReadOnly/IsWriteOnly checks commented out (// TODO:). That is why Uno's extra protected set on a read-only WinUI property was never flagged — the sync generator structurally cannot catch accessor divergence.
  • Given_Control.When_Padding_Set_In_SizeChanged carries a stale [Ignore] reason ("ContentControl … is a superclass of UserControl on Uno" — untrue since BC14). Left alone deliberately: it applies to the WinAppSDK head only and the real reason for skipping there couldn't be determined, so inventing a new reason would be worse.

🤖 Generated with Claude Code

Xiaoy312 and others added 4 commits August 24, 2026 16:22
ContentControl skipped the ContentPresenter and parented Content directly
whenever it had no Template and its default style declared none. The bypass
was an Android 4.4 stack-depth workaround and had already stopped engaging:
Uno.UI is Skia-only, so _IsNetStdRef is always true and the netstdref-gated
default ControlTemplate was always applied.

Also drops the Type-keyed HasDefaultTemplate memo (and the ALC-teardown sweep
that existed only to unpin it), ButtonBase's dead RegisterEvents plumbing, and
the ApplyTemplate escape hatch the bypass required.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Adds the PackageDiffIgnore entries for the ContentControl members removed with
the bypass, a migration note for ContentControl subclasses that ship no
ControlTemplate, and the design doc recording that the bypass was already
inert before this change.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
ContentTemplateRoot is WinUI API on ContentControl (get-only) and does not
exist on WinUI's ContentPresenter, yet only the presenter ever had a value:
ContentControl.ContentTemplateRoot returned null for every control once the
bypass stopped engaging. The presenter now reports its materialized root to
its templated parent, mirroring CContentPresenter, and its own property drops
to private.

Sibling presenters sharing a templated parent are told apart by comparing the
Content dependency-property values; the CLR properties cannot be used because
ContentControl.Content falls back to DataContext when the DP is unset.

Fixes the SelectorItem automation-name fallback and the ItemsRepeaterScrollHost
transforms, which both read the null value. Retires the sync-generator type
carve-out for ContentTemplateRoot, whose native-view premise is gone.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Records the ContentPresenter bypass removal in the Phase 6 checklist with a
link to its impact spec, notes that it supersedes BC36's "internal, not
private" decision for ContentPresenter.ContentTemplateRoot, and adds a
sequencing note against BC01 since the new report site uses GetTemplatedParent.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@github-actions github-actions Bot added area/build Categorizes an issue or PR as relevant to build infrastructure area/automation Categorizes an issue or PR as relevant to project automation kind/documentation labels Aug 24, 2026
Xiaoy312 and others added 2 commits August 24, 2026 18:35
…v/xygu/20260824/remove-contentpresenter-bypass

# Conflicts:
#	src/Uno.UI/UI/Xaml/Style/Generic/Generic.xaml
The base branch retired the netstdref/not_netstdref prefixes while this was in
flight; the ContentControl Template setter now carries not_winappsdk, which is
unconditionally included for the Skia-only Uno.UI. Same conclusion, so the
Generic.xaml edit is dropped and the docs describe the current spelling.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 229908 found UI Test snapshots differences: skia-linux-screenshots: 73, skia-windows-screenshots: 188

Details
  • skia-linux-screenshots: 73 changed over 2366

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Focus_FocusVisual_Properties.png-dark
    • DropDownButtonPage.png-dark
    • Buttons.png
    • DynamicFont.png
    • ElementLevelTheme.png-dark
    • ElementLevelTheme.png
    • Examples.png
    • ImageBrush_Stretch.png
    • ImageIconPage.png-dark
    • ImageIconPage.png
    • ContextRequested.png-dark
    • Attributed_text_FontSize_Changing.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • ExpanderColorValidationPage.png-dark
    • ExpanderColorValidationPage.png
    • Gamepad_CurrentReading.png-dark
    • Gamepad_CurrentReading.png
    • Gamepad_Enumeration.png-dark
    • ImageBrushInList.png-dark
  • skia-windows-screenshots: 188 changed over 2368

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Attributed_text_FontSize_Changing.png-dark
    • Contacts_Pick.png-dark
    • Contacts_Pick.png
    • Battery.png-dark
    • BitmapImage_vs_SvgImageSource.png-dark
    • BitmapImage_vs_SvgImageSource.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • Buttons.png-dark
    • ChatBox.png-dark
    • ChatBox.png
    • Examples.png
    • GeolocatorPositionChanged.png-dark
    • GeolocatorPositionChanged.png
    • Focus_FocusVisual_Properties.png-dark
    • Focus_FocusVisual_Properties.png
    • ExpanderColorValidationPage.png-dark
    • Focus_FocusState.png-dark

@mergify

mergify Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 230006 found UI Test snapshots differences: skia-linux-screenshots: 73, skia-windows-screenshots: 123

Details
  • skia-linux-screenshots: 73 changed over 2366

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Examples.png
    • ImageBrushInList.png-dark
    • ImageBrushInList.png
    • DisplayInformation.png-dark
    • DisplayInformation.png
    • Focus_FocusVisual_Properties.png-dark
    • ExpanderColorValidationPage.png-dark
    • ExpanderColorValidationPage.png
    • ImageIconPage.png-dark
    • ImageIconPage.png
    • Gamepad_CurrentReading.png-dark
    • Gamepad_CurrentReading.png
    • Gamepad_Enumeration.png-dark
    • Attributed_text_FontSize_Changing.png
    • ButtonClippingTestsControl.png-dark
    • CalendarView_Theming.png-dark
    • ButtonClippingTestsControl.png
    • ClipboardTests.png-dark
    • ClipboardTests.png
    • ContextRequested.png-dark
  • skia-windows-screenshots: 123 changed over 2366

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Battery.png-dark
    • Battery.png
    • Gamepad_CurrentReading.png-dark
    • Gamepad_CurrentReading.png
    • Gamepad_Enumeration.png-dark
    • Gamepad_Enumeration.png
    • Attributed_text_FontSize_Changing.png-dark
    • Haptics.VibrationDevice.png-dark
    • Haptics.VibrationDevice.png
    • ButtonClippingTestsControl.png-dark
    • ExpanderColorValidationPage.png-dark
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
    • CalendarView_Theming.png-dark
    • DropDownButtonPage.png-dark
    • Attributed_text_FontSize_Changing.png
    • ImageSourceUrlMsAppDataScheme.png-dark
    • ImageSourceUrlMsAppDataScheme.png
    • ClipboardTests.png-dark
    • Contacts_Pick.png-dark

@unodevops

Copy link
Copy Markdown
Contributor

@Xiaoy312 Xiaoy312 added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 25, 2026
@unodevops

Copy link
Copy Markdown
Contributor

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

BC01 (#24070) landed on the base while this branch was in flight, adding
two suites that host a bare ContentPresenter and read its
ContentTemplateRoot. This branch makes that property private, so the
merge broke every Build Samples App job with the same three CS1061.

A standalone presenter has no ContentControl to report to, so these read
the materialized root as the presenter's single visual child -- the same
pattern already used by the ContentControl tests here.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 230145 found UI Test snapshots differences: skia-linux-screenshots: 73, skia-windows-screenshots: 166

Details
  • skia-linux-screenshots: 73 changed over 2366

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • DynamicFont.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • ClipboardTests.png-dark
    • ClipboardTests.png
    • ContentControl_Inheritance.png
    • ExpanderColorValidationPage.png-dark
    • ExpanderColorValidationPage.png
    • Image_Margin_Large.png
    • ImageBrush_Stretch.png
    • DisplayInformation.png-dark
    • DisplayInformation.png
    • ContextRequested.png-dark
    • DropDownButtonPage.png-dark
    • Focus_FocusVisual_Properties.png-dark
    • Gamepad_CurrentReading.png-dark
    • Gamepad_CurrentReading.png
    • Gamepad_Enumeration.png-dark
    • ImageIconPage.png-dark
    • ImageIconPage.png
  • skia-windows-screenshots: 166 changed over 2368

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Gamepad_CurrentReading.png-dark
    • Gamepad_Enumeration.png-dark
    • ExpanderColorValidationPage.png-dark
    • Focus_FocusState.png-dark
    • Focus_FocusState.png
    • Examples.png
    • GetFocus.png-dark
    • GetFocus.png
    • DropDownButtonPage.png-dark
    • DropDownButtonPage.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • ClipboardTests.png-dark
    • DisplayInformation.png-dark
    • Dopes.png-dark
    • ContentPresenter_Padding.png-dark
    • ContentPresenter_Padding.png
    • DynamicFont.png-dark
    • DynamicFont.png
    • ImageBrushInList.png-dark

@MartinZikmund
MartinZikmund merged commit 2714eb0 into feature/breakingchanges Aug 25, 2026
54 checks passed
@MartinZikmund
MartinZikmund deleted the dev/xygu/20260824/remove-contentpresenter-bypass branch August 25, 2026 17:23
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/build Categorizes an issue or PR as relevant to build infrastructure do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants