Skip to content

[Controls][Net11][WIP]VisualElement: Obsolete BackgroundColor in favor of Background - #36130

Draft
KarthikRajaKalaimani wants to merge 47 commits into
dotnet:net11.0from
KarthikRajaKalaimani:fix-28854
Draft

[Controls][Net11][WIP]VisualElement: Obsolete BackgroundColor in favor of Background#36130
KarthikRajaKalaimani wants to merge 47 commits into
dotnet:net11.0from
KarthikRajaKalaimani:fix-28854

Conversation

@KarthikRajaKalaimani

@KarthikRajaKalaimani KarthikRajaKalaimani commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Description of Change

VisualElement.BackgroundColor overlaps with Background, which already supports solid colors through the implicit Color to SolidColorBrush conversion and also supports gradient brushes. Maintaining both APIs has caused mapper and control behavior to diverge.

This change marks the legacy color APIs obsolete in favor of their brush-based replacements:

  • VisualElement.BackgroundColor and BackgroundColorProperty -> Background and BackgroundProperty
  • IBorderElement.BackgroundColor and IsBackgroundColorSet() -> Background and IsBackgroundSet()
  • VisualElement.MapBackgroundColor() -> MapBackground()

Existing applications remain runtime-compatible. Values set through BackgroundColor still flow through IView.Background, and the legacy mapper entry remains available while forwarding to MapBackground.

Implementation Details

  • Migrates framework-owned handlers, compatibility renderers, controls, templates, CSS registration, and sample template XAML to Background.
  • Keeps narrowly scoped compatibility bridges for RadioButton and TitleBar template bindings that must continue reacting to the obsolete property.
  • Preserves Page.BackgroundImageSource behavior: a locally set image can override an implicit Page.Background style, while an equally specific or local Background keeps its existing precedence.
  • Keeps the TitleBar property-change bridge active when the same title bar is detached and reattached.
  • Removes the project-wide device-test CS0618 suppression. Framework-owned test setup now uses Background; tests intentionally validating BackgroundColor use scoped pragmas.
  • Corrects an Android Shell handler teardown failure exposed by the latest net11.0 device tests: FragmentManager retains ownership of its wrapper fragment, and the test host now waits for fragment destruction before starting the next test.

Tests

  • Adds unit coverage for implicit Page background styles, local background precedence, and BackgroundImageSource.
  • Adds unit coverage for TitleBar bridge notifications after detach/reattach.
  • Builds the Controls device-test project for Android, iOS, and Mac Catalyst without a project-wide obsolete-warning suppression.
  • Runs the Android Shell device-test category through full fragment teardown.

Migration Guide

Before After
view.BackgroundColor = Colors.Red; view.Background = Colors.Red;
<Label BackgroundColor="Red" /> <Label Background="Red" />
VisualElement.MapBackgroundColor(handler, view); VisualElement.MapBackground(handler, view);

Compatibility Guidance

Do not suppress CS0618 for an entire project. Framework code should migrate to Background; scoped suppressions should be limited to compatibility paths and tests that intentionally exercise the obsolete API.

Issues Fixed

Fixes #28854

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 36130

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 36130"

@dotnet-policy-service dotnet-policy-service Bot added the community ✨ Community Contribution label Jun 25, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Hey there @@KarthikRajaKalaimani! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@vishnumenon2684

Copy link
Copy Markdown
Contributor

/azp run maui-pr-uitests , maui-pr-devicetests

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 2 pipeline(s).

@vishnumenon2684

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 3 pipeline(s).

@KarthikRajaKalaimani
KarthikRajaKalaimani force-pushed the fix-28854 branch 2 times, most recently from 31ec74e to ef245cd Compare July 2, 2026 09:23
@vishnumenon2684

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 3 pipeline(s).

@vishnumenon2684

Copy link
Copy Markdown
Contributor

/azp run maui-pr-uitests

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@kubaflo

This comment has been minimized.

@github-actions github-actions Bot added the s/agent-review-in-progress AI review is currently running for this PR label Jul 5, 2026

@MauiBot MauiBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Expert Review — 2 findings

See inline comments for details.

Comment thread src/Controls/src/Core/VisualElement/VisualElement.cs
@MauiBot MauiBot added s/agent-gate-failed AI could not verify tests catch the bug s/agent-fix-pr-picked AI could not beat the PR fix - PR is the best among all candidates s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review) labels Jul 5, 2026
MauiBot

This comment was marked as outdated.

@MauiBot MauiBot removed the s/agent-review-in-progress AI review is currently running for this PR label Jul 6, 2026
@kubaflo

kubaflo commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

@jfversluis could you please have a look?

KarthikRajaKalaimani and others added 15 commits July 31, 2026 13:52
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Preserve BackgroundImageSource precedence over implicit styles, keep the TitleBar compatibility bridge active after reattachment, and scope obsolete warnings in device tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 51b16329-8bf7-4952-960e-d9e9313e204d
@kubaflo

kubaflo commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@kubaflo

kubaflo commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

/azp run maui-pr-devicetests

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@kubaflo

kubaflo commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

/azp run maui-pr-devicetests

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 51b16329-8bf7-4952-960e-d9e9313e204d
@kubaflo

kubaflo commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@kubaflo kubaflo 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.

Why it has the label do-not-merge?

@KarthikRajaKalaimani

Copy link
Copy Markdown
Contributor Author

Why it has the label do-not-merge?

We plan to include this in .NET 12 as part of the full migration from BackgroundColor to the Background property across all source files.

@kubaflo

This comment has been minimized.

@MauiBot

MauiBot commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

⚠️ Merge Conflict Detected — This PR has merge conflicts with its target branch. Please rebase onto the target branch and resolve the conflicts.

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

Labels

area-controls-general General issues that span multiple controls, or common base classes such as View or Element community ✨ Community Contribution do-not-merge Don't merge this PR partner/syncfusion Issues / PR's with Syncfusion collaboration platform/android platform/ios platform/macos macOS / Mac Catalyst platform/windows s/agent-fix-win AI found a better alternative fix than the PR s/agent-gate-failed AI could not verify tests catch the bug s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants