Add BadgeText, BadgeColor, and BadgeTextColor support to ToolbarItem#34669
Add BadgeText, BadgeColor, and BadgeTextColor support to ToolbarItem#34669jfversluis wants to merge 9 commits intonet11.0from
Conversation
Extends badge support from Shell bottom tabs (PR #34659) to ToolbarItems. Uses native platform APIs: Android BadgeUtils/BadgeDrawable, iOS 26+ UIBarButtonItem.badge, and Windows InfoBadge overlay. Includes 17 unit tests, UI test page, and sample gallery page. Fixes #8305 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Replace deprecated Frame with Border control - Add System and Microsoft.Maui usings - Fix nullable Color? parameter in SetBadgeColor Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 34669Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 34669" |
There was a problem hiding this comment.
Pull request overview
Adds cross-platform badge support to ToolbarItem via new BadgeText/BadgeColor bindable properties, with platform renderers and accompanying tests/samples.
Changes:
- Introduces
ToolbarItem.BadgeTextandToolbarItem.BadgeColorplus PublicAPI updates. - Implements badge rendering on Android (Material
BadgeDrawable), iOS/MacCatalyst (nativeUIBarButtonItembadge), and Windows (InfoBadgeoverlay). - Adds unit tests, UI tests (HostApp + Appium), and a sample gallery page demonstrating toolbar badges.
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 14 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Controls/src/Core/Toolbar/ToolbarItem.cs | Adds BadgeText/BadgeColor bindable properties and XML docs. |
| src/Controls/src/Core/Platform/Android/Extensions/ToolbarExtensions.cs | Renders badges with BadgeDrawable, includes lifecycle tracking and async attachment logic. |
| src/Controls/src/Core/Compatibility/iOS/Extensions/ToolbarItemExtensions.cs | Updates iOS primary toolbar item wrapper to apply native badge when supported. |
| src/Controls/src/Core/Toolbar/Toolbar.Windows.cs | Adds InfoBadge overlay and updates it on ToolbarItem property changes. |
| src/Controls/src/Core/PublicAPI/*/PublicAPI.Unshipped.txt | Adds unshipped PublicAPI entries for the new ToolbarItem badge members across TFMs. |
| src/Controls/tests/Core.UnitTests/ToolbarItemBadgeTests.cs | Unit tests for default values, binding, and property-changed behavior. |
| src/Controls/tests/TestCases.HostApp/Issues/Issue8305_Toolbar.cs | HostApp page used by UITests to exercise badge scenarios. |
| src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue8305_Toolbar.cs | Appium UI tests + screenshots for toolbar badge scenarios. |
| src/Controls/samples/Controls.Sample/ViewModels/CoreViewModel.cs | Registers the new sample page in the gallery navigation. |
| src/Controls/samples/Controls.Sample/Pages/Core/ToolbarBadgePage.cs | Sample page demonstrating numeric/text badges and color changes. |
| src/Core/maps/src/PublicAPI/net/PublicAPI.Unshipped.txt | Removes duplicate/unannotated entries for IMap.ShowInfoWindow/HideInfoWindow. |
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue8305_Toolbar.cs
Outdated
Show resolved
Hide resolved
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue8305_Toolbar.cs
Outdated
Show resolved
Hide resolved
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue8305_Toolbar.cs
Show resolved
Hide resolved
The test file was missing NUnit.Framework, UITest.Appium, and UITest.Core usings, and used incorrect namespace causing build failures in Controls.TestCases.Mac.Tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Hi @jfversluis Nice to have: |
…text-only items, Android cleanup - Add BadgeTextColor property to ToolbarItem for foreground text color customization - Android: BadgeDrawable.BadgeTextColor - iOS/MacCatalyst 26+: UIBarButtonItemBadge.ForegroundColor - Windows: InfoBadge.Foreground brush - Add retryTimeout to all VerifyScreenshot() calls for async Android badge rendering - Fix Windows text-only toolbar items: wrap in Grid+InfoBadge overlay - Add ReferenceEquals guard in Android toolbar.Post() callback for recycled menu items - Clean up all badge drawables in DisposeMenuItems - Add 7 unit tests for BadgeTextColor (24 total) - Update all 7 PublicAPI.Unshipped.txt files - Add Badge Text Color section to sample gallery page Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Thanks for the feedback @AlleSchonWeg! Great to hear you've implemented toolbar badges in your app. BadgeTextColor — Implemented in 374ae80! New
IsVisible — Setting BadgeTextFont — This is tricky as platform support varies significantly. Android's |
|
Thanks for implementing my suggestion @jfversluis
I find setting As i implemented my badge i observed a crazy behaviour on android. I added the badge on a toolbar item on one page and on another page(s) the badge also appeared. But only the badge. The icon, color etc. was correct. I don't know if i had done something wrong. Perhaps some internal caching or whatever. My setup was a TabbedPage with 4 tabs. Every tab had a NavigationPage and on the first Root ContentPage i had the item with badge plus another item without badge. The other Root ContentPages had also toolbar items but without badges. Perhaps this info can help with your implementation. |
|
/azp run maui-pr-uitests |
Change BadgeText semantics: null = no badge, empty string = dot indicator, non-empty string = text/count badge. Previously both null and empty string hid the badge. Platform implementations: - Android: ClearNumber() on BadgeDrawable for dot mode - iOS: UIBarButtonItemBadge.Create(0) for dot indicator - Windows: Value = -1 for empty string (dot indicator) Added 3 unit tests for dot badge behavior. Updated XML docs to document null vs empty string semantics. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Implemented dot badge support! You can now set
Platform-specific behavior:
This applies to both PRs (#34659 Shell tabs and #34669 ToolbarItems). |
|
/azp run maui-pr |
|
/azp run maui-pr-uitests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
1 similar comment
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
also this issue #23802 will be solved by this pr |
Remove duplicate entries that caused RS0025 build errors. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
/azp run maui-pr |
|
/azp run maui-pr-uitests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
1 similar comment
|
Azure Pipelines successfully started running 1 pipeline(s). |
- Remove WaitForElement for ToolbarItem AutomationId (not accessible via Appium on WinUI) — wait for page StatusLabel instead - Add Windows reference screenshots for ToolbarItemBadgesClear and ToolbarItemBadgeColorChanges tests Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
/azp run maui-pr-uitests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run maui-pr |
|
Azure Pipelines successfully started running 1 pipeline(s). |
- Add 3 iOS (ios-26) reference screenshots: ToolbarItemBadgesDisplay, ToolbarItemBadgesClear, ToolbarItemBadgeColorChanges - Add 3 Android reference screenshots for the same tests - Generated from CI build 1355044 snapshot artifacts Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
/azp run maui-pr-uitests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
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
Adds
BadgeText,BadgeColor, andBadgeTextColorproperties toToolbarItem, enabling badge notifications on toolbar items across all platforms.Fixes #8305 (partial - ToolbarItem badges; Shell tab badges handled in #34659)
API
Badge Text Semantics
null""(empty string)"3""New"Platform Support
BadgeDrawablevia Material ComponentsClearNumber()for dot mode. UsesBadgeUtils.attachBadgeDrawable()with race condition guard.UIBarButtonItem.badgeAPICreate(0)for dot. Requires iOS 26+, no-op on earlier versions.InfoBadgeoverlay onAppBarButtonProperties
BadgeTextstring?null= hidden,""= dot, non-empty = text/count.BadgeColorColor?null= platform default.BadgeTextColorColor?null= platform default (typically white).Changes
ToolbarItem.cs— AddedBadgeText,BadgeColor,BadgeTextColorbindable properties with XML docsToolbarExtensions.cs(Android) — Badge rendering viaBadgeDrawablewithConcurrentDictionarytracking, stale-update guard, and cleanup inDisposeMenuItemsToolbarItemExtensions.cs(iOS) — iOS 26+ native badge API with platform version checkToolbar.Windows.cs—InfoBadgeoverlay onAppBarButtoncontent grid (both icon and text-only items)ToolbarItemBadgeTests.csToolbarBadgePage.cs