Repository navigation
[Windows] Fix Dynamic ShellContent Title Updates at Runtime - #35998
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 35998Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 35998" |
This comment has been minimized.
This comment has been minimized.
kubaflo
left a comment
There was a problem hiding this comment.
Could you please check the ai's suggestions?
…sLayout is set for Tablet but not on mobile devices (dotnet#26152)" This reverts commit 0ddc794.
…msLayout is set for Tablet but not on mobile devices (dotnet#26152)" This reverts commit 4b9074c.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
When every changed product file is platform-specific for a DIFFERENT platform than the gate (e.g. an iOS-only fix reviewed on the ANDROID gate), those files are excluded from this platform's TFM and never compile into its binary, so the without-fix and with-fix runs are byte-identical no-ops. The gate can only ever reach INCONCLUSIVE 'no match' — after spending the full build + device-test budget twice (#35998 ran the Android UI test 2x2342s ~= 78 min to prove nothing). Detect this up front via the existing conservative Test-FixIrrelevantToPlatform check (returns true ONLY when there is a product file and every product file targets another platform) and skip the whole revert/build/run cycle, writing the same INCONCLUSIVE report (exit 3) the post-hoc $fixPlatformMismatch classifier would produce. The verdict is unchanged; only the wasted device time is removed. A report is written (no 'ENV ERROR' text) so Review-PR.ps1 treats it as a clean INCONCLUSIVE with no retries. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 15d2af20-e4ab-4e88-9011-cfbd83513bc0
| { | ||
| if (shellContent.Parent is ShellSection shellSection && shellSection.Parent is ShellItem shellItem && shellItem.Handler is ShellItemHandler shellItemHandler) | ||
| { | ||
| shellItemHandler.UpdateTitle(); |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…ing its own running .dotnet Root cause (PR #35998 builds 14665168 + 14676303): common/provision.yml installs the local SDK into ./.dotnet and prepends it to PATH, so the cake 'dotnet' target runs 'dotnet build src/DotNet/DotNet.csproj' USING ./.dotnet/dotnet.exe. That project's _InstallDotNet target does <RemoveDir ./.dotnet>, deleting the very dotnet.exe running it. On Windows a running exe can't be deleted -> MSB3231 'Access to the path dotnet.exe is denied' -> ./.dotnet/sdk left half-removed ('hostpolicy.dll not found') -> the whole Review stage aborts and posts the MAUI_BOT_REVIEW_INCOMPLETE warning. Windows-only (Unix can unlink a running exe). The previous 'Release .dotnet locks' step tried to kill a supposed lingering prior-run build server, but the locking process is cake's OWN dotnet build, so killing never helped. Fix (both Review and Deep stages, Windows-only pre-step): if provision.yml's ./.dotnet is healthy ('dotnet --version' succeeds), write its _InstallDotNet incremental stamp (./.dotnet/.stamp) so cake SKIPS the self-deleting RemoveDir/reinstall and reuses that SDK (workload targets, with their own stamps, still run). If ./.dotnet is already broken from a prior attempt, remove it so cake reinstalls cleanly. Validated the health->stamp / broken->remove / absent->noop branches with a pwsh harness. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 15d2af20-e4ab-4e88-9011-cfbd83513bc0
This comment has been minimized.
This comment has been minimized.
MauiBot
left a comment
There was a problem hiding this comment.
AI Review Summary
@devanathan-vaithiyanathan — new AI review results are available based on this last commit:
0cdaa9e. To request a fresh review after new comments or commits, comment/review rerun.
🗂️ Review Sessions — click to expand
🚦 Gate — Test Before & After Fix
Gate Result: ✅ PASSED
Platform: WINDOWS · Base: main · Merge base: f8099fb7
| Test | Without Fix (expect FAIL) | With Fix (expect PASS) |
|---|---|---|
🖥️ Issue26049 Issue26049 |
✅ FAIL — 617s | ✅ PASS — 487s |
🔴 Without fix — 🖥️ Issue26049: FAIL ✅ · 617s
Error-relevant lines (filtered from the build log):
at UITest.Appium.HelperExtensions.Wait(Func`1 query, Func`2 satisfactory, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2757
at UITest.Appium.HelperExtensions.WaitForAtLeastOne(Func`1 query, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2784
at UITest.Appium.HelperExtensions.WaitForElement(IApp app, String marked, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency, Nullable`1 postTimeout) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 793
at Microsoft.Maui.TestCases.Tests.Issues.Issue26049.VerifyFirstShellContentTitle() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue26049.cs:line 20
at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
at Microsoft.Maui.TestCases.Tests.Issues.Issue26049.TabNavigationViewItemIfWindows() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue26049.cs:line 53
at Microsoft.Maui.TestCases.Tests.Issues.Issue26049.VerifyNewlyAddedShellContentTitle() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue26049.cs:line 30
at Microsoft.Maui.TestCases.Tests.Issues.Issue26049.VerifyExistingTabTitle() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue26049.cs:line 42
🟢 With fix — 🖥️ Issue26049: PASS ✅ · 487s
(no coded error found; showing last 1200 chars)
nit3TestExecutor discovered 3 of 3 NUnit test cases using Current Discovery mode, Non-Explicit run
>>>>> 7/16/2026 6:50:59 PM FixtureSetup for Issue26049(Windows)
>>>>> 7/16/2026 6:51:08 PM VerifyFirstShellContentTitle Start
>>>>> 7/16/2026 6:51:12 PM VerifyFirstShellContentTitle Stop
Passed VerifyFirstShellContentTitle [3 s]
>>>>> 7/16/2026 6:51:12 PM VerifyNewlyAddedShellContentTitle Start
>>>>> 7/16/2026 6:51:16 PM VerifyNewlyAddedShellContentTitle Stop
Passed VerifyNewlyAddedShellContentTitle [3 s]
>>>>> 7/16/2026 6:51:16 PM VerifyExistingTabTitle Start
>>>>> 7/16/2026 6:51:20 PM VerifyExistingTabTitle Stop
Passed VerifyExistingTabTitle [3 s]
NUnit Adapter 4.5.0.0: Test execution complete
[xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.8.2+699d445a1a (64-bit .NET 10.0.0)
[xUnit.net 00:00:00.13] Discovering: Controls.TestCases.WinUI.Tests
[xUnit.net 00:00:00.35] Discovered: Controls.TestCases.WinUI.Tests
Results File: D:\a\1\s\CustomAgentLogsTmp\UITests\TestResults\Issue26049.trx
Test Run Successful.
Total tests: 3
Passed: 3
Total time: 32.6961 Seconds
>>> TRX_RESULT_FILE: D:\a\1\s\CustomAgentLogsTmp\UITests\TestResults\Issue26049.trx
📁 Fix files reverted (3 files)
src/Controls/src/Core/Handlers/Shell/ShellContentHandler.Windows.cssrc/Controls/src/Core/Handlers/Shell/ShellItemHandler.Windows.cssrc/Controls/src/Core/Handlers/Shell/ShellSectionHandler.Windows.cs
New files (not reverted):
src/Controls/src/Core/Platform/Windows/Extensions/ShellContentExtensions.cs
📱 UI Tests — Shell
Detected UI test categories: Shell
✅ Deep UI tests — 278 passed, 0 failed across 1 category on platform-pool agent (replaces in-process counts above).
🧪 UI Test Execution Results (deep, platform pool)
| Category | Tests | Snapshot diffs |
|---|---|---|
Shell |
278/278 ✓ | — |
📎 Download drop-deep-uitests artifact (TRX + snapshot diffs) |
📋 Pre-Flight — Context & Validation
Issue: #27494 - [Windows/Android] Runtime Added ShellContent Title Not Updating in TabBar
PR: #35998 - [Windows] Fix Dynamic ShellContent Title Updates at Runtime
Platforms Affected: Windows, Android (issue); PR implementation targets Windows
Files Changed: 4 implementation, 5 test/snapshot
Key Findings
- PR changes Windows Shell handler plumbing so
ShellContent.Titlechanges refresh the parent ShellItem tab/menu title, including dynamically added ShellContent. - Linked issue #27494 is verified on Windows and Android, but the PR implementation and enabled UI coverage are Windows-only; the Android test remains excluded.
- Gate result supplied by caller: ✅ PASSED — tests fail without fix and pass with PR fix. Gate was not re-run.
ghCLI metadata/check queries are blocked by missing authentication; unauthenticated REST API was used for PR/issue context.- Impacted UI test category: Shell.
Code Review Summary
Verdict: NEEDS_CHANGES
Confidence: low
Errors: 1 | Warnings: 1 | Suggestions: 0
Key code review findings:
- ✗
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue26049.cs:1keeps the test excluded on Android while PR body saysFixes #27494; no Android Shell implementation files changed. - ⚠
src/Controls/src/Core/Platform/Windows/Extensions/ShellContentExtensions.cs:11callsshellItemHandler.UpdateTitle()directly, bypassing handler mapper extensibility; handler guidance prefersUpdateValue(nameof(ShellItem.Title)).
Fix Candidates
| # | Source | Approach | Test Result | Files Changed | Notes |
|---|---|---|---|---|---|
| PR | PR #35998 | Windows ShellSectionHandler tracks ShellContent.PropertyChanged, updates parent ShellItemHandler title, and refreshes menu items for dynamic changes. |
✅ PASSED (Gate) | ShellContentHandler.Windows.cs, ShellItemHandler.Windows.cs, ShellSectionHandler.Windows.cs, ShellContentExtensions.cs, UI test files/snapshots |
Original PR; Android remains excluded. |
🔬 Code Review — Deep Analysis
Code Review — PR #35998
Independent Assessment
What this changes: Windows Shell now observes ShellContent.PropertyChanged from ShellSectionHandler.Windows and refreshes the parent ShellItemHandler menu/title when ShellContent.Title changes. It also de-duplicates ShellSection PropertyChanged subscriptions in ShellItemHandler, removes the old ShellContentHandler title mapper, and enables Windows UI screenshot coverage for Issue26049.
Inferred motivation: Fix runtime/dynamically-added ShellContent.Title updates not appearing in the Windows tab UI.
Reconciliation with PR Narrative
Author claims: Windows fix for dynamic ShellContent title updates; PR body still says Fixes #27494.
Agreement/disagreement: The implementation is Windows-only and appears aimed at the Windows root cause. However, #27494 is verified for Windows and Android, and this PR still excludes the regression test on Android.
Prior Review Reconciliation
| Prior ❌ Error Finding | Source | Status | Evidence |
|---|---|---|---|
Duplicate OnShellContentPropertyChanged / stale _subscribedItems broke build |
MauiBot inline review | ✅ Fixed | Current ShellSectionHandler.Windows.cs has one handler and uses _trackedShellContents consistently. |
Repeated title refresh accumulated duplicate ShellItemHandler subscriptions |
MauiBot inline review | ✅ Fixed | ShellItemHandler.Windows.cs:214-223 unsubscribes tracked sections before rebuilding. |
| PR closes Windows/Android issue while Android remains excluded | MauiBot summaries | ❌ Unresolved | PR body still says Fixes #27494; Issue26049.cs:1 remains #if TEST_FAILS_ON_ANDROID; no Android implementation files changed. |
| Windows screenshot baseline mismatch in prior gate | MauiBot summary | ❌ Unresolved / unverified | No fresh UI-test evidence found in current required checks; prior ❌ cannot be confirmed fixed. |
Blast Radius Assessment
- Runs for all instances: Windows Shell instances using tab/menu ShellContent.
- Startup impact: No direct app-startup static initialization.
- Static/shared state: No new static state; new per-handler subscription tracking.
CI Status
- Required-check result:
gh pr checks --requiredunavailable becauseghis unauthenticated. API fallback shows current headmaui-pr/ Build Analysis failing. - Classification: failure appears likely infra/unrelated (
RunOniOS_MauiReleaseTrimFull ARM64canceled after 45-minute timeout), but CI is not green. - Action taken: invoked
azdo-build-investigator;ci-analysiswas unavailable; confidence capped low.
Findings
❌ Error — PR still auto-closes an Android+Windows issue while Android remains disabled
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue26049.cs:1 keeps the test excluded on Android, and the diff contains no Android Shell implementation. Since the PR body says Fixes #27494, merging would close a verified Windows/Android bug with the Android path still unfixed/unvalidated.
⚠️ Warning — Direct UpdateTitle() bypasses handler mapper extensibility
src/Controls/src/Core/Platform/Windows/Extensions/ShellContentExtensions.cs:11 calls shellItemHandler.UpdateTitle() directly. Handler guidance prefers UpdateValue(nameof(ShellItem.Title)) so ShellItemHandler.Mapper customizations (AppendToMapping/PrependToMapping) still run.
Failure-Mode Probing
- Repeated title changes: current
HashSetcleanup prevents duplicate ShellSection subscriptions. - Disconnect/reconnect: tracked ShellContent/ShellSection subscriptions are cleared during disconnect.
- Null parent/handler: extension uses pattern checks and no-ops safely.
- Android scenario from #27494: still unchanged and test-excluded.
- Mapper customization: direct call skips custom mapper delegates.
Verdict: NEEDS_CHANGES
Confidence: low
Summary: The Windows handler direction looks mostly sound, and earlier build/subscription issues appear fixed. But an unresolved prior ❌ remains: the PR still claims to fix/close #27494 while Android is excluded and unfixed; CI is also not green/fully verifiable.
🛠️ Fix — Analysis & Comparison
Fix Candidates
| # | Source | Approach | Test Result | Files Changed | Notes |
|---|---|---|---|---|---|
| 1 | try-fix-1 | Move ShellContent title observation into ShellItemHandler.MapMenuItems(), subscribe to every displayed ShellSection and child ShellContent, and update the matching NavigationViewItemViewModel.Content directly. |
✅ PASS — Issue26049 Windows UI tests passed (3/3) |
3 files | Better Windows candidate than PR fix: self-contained in the UI-owning handler, avoids cross-handler extension call, avoids direct UpdateTitle() mapper bypass, and avoids full menu rebuild on each title change. |
| PR | PR #35998 | ShellSectionHandler.Windows tracks ShellContent.PropertyChanged and calls parent ShellItemHandler.UpdateTitle() through ShellContentExtensions. |
✅ PASSED (Gate) | 4 implementation files + tests/snapshots | Original PR fix; Windows-only and still leaves Android excluded. |
Candidate Details
try-fix-1 — ShellItemHandler-owned subscription
Approach: Instead of having ShellSectionHandler track ShellContent.PropertyChanged and call back into ShellItemHandler, the candidate puts all menu/title subscriptions in ShellItemHandler, the handler that owns the WinUI NavigationView item view models. On title changes, it updates the existing NavigationViewItemViewModel.Content for either top-level tabs or sub-menu items.
Diff: See CustomAgentLogsTmp/PRState/35998/PRAgent/try-fix/attempt-1/fix.diff and CustomAgentLogsTmp/PRState/35998/PRAgent/try-fix-1/content.md.
Test results: pwsh .github/scripts/BuildAndRunHostApp.ps1 -Platform windows -TestFilter "Issue26049" passed:
Build succeeded.
Passed VerifyFirstShellContentTitle
Passed VerifyNewlyAddedShellContentTitle
Passed VerifyExistingTabTitle
Passed: 3
All tests passed
Failure analysis: Final candidate passed. The internal first iteration only subscribed implicit-routing sections and failed VerifyExistingTabTitle; the attempt was corrected to subscribe all ShellContent children regardless of implicit/explicit section shape.
Self-review: 0 findings (reviewer-findings.json contains []).
Cross-Pollination
| Model | Round | New Ideas? | Details |
|---|---|---|---|
| claude-opus-4.6 | 1 | Yes | ShellItemHandler-owned subscription/update path generated and tested as try-fix-1. |
Exhausted: No — loop stopped because try-fix-1 passed all Windows regression tests and is demonstrably better than the PR's Windows fix.
Selected Fix: Candidate #1 — it passes the same targeted Windows UI regression tests while reducing handler coupling, avoiding direct mapper-method bypass, and updating only the affected view model instead of rebuilding all menu items on each ShellContent title change.
📝 Recommended PR Title & Description
Assessment: ✏️ Recommend updating — the current description describes the raw PR's ShellSectionHandler.Windows approach, but the winning candidate is try-fix-1, which moves the Windows title observation/update ownership into ShellItemHandler.Windows.
Recommended title
[Windows] Shell: Fix runtime ShellContent title updates
Recommended description
### Root Cause
On Windows, runtime `ShellContent.Title` changes were not reflected in the Shell tab/menu UI for dynamically added ShellContent because the Windows NavigationView item models were not observing all displayed ShellContent title changes after the menu was built.
### Description of Change
Windows: Move runtime ShellContent title observation into `ShellItemHandler.Windows`, the handler that owns the WinUI NavigationView menu item view models. `ShellItemHandler` tracks the Shell sections and child ShellContent items used by the menu, unsubscribes previous subscriptions when rebuilding menu items, and updates the matching `NavigationViewItemViewModel.Content` directly when a title changes.
This keeps the title refresh path local to the UI-owning handler, avoids cross-handler callbacks from `ShellSectionHandler` to `ShellItemHandler`, and avoids rebuilding the entire menu for each ShellContent title change.
### Issues Fixed
Fixes #27494
### Regarding test case
Added a test case for runtime-added ShellContent title updates in PR #26062. These tests are applicable to this change as well.
**Tested the behavior in the following platforms.**
- [ ] Android
- [x] Windows
- [ ] iOS
- [ ] Mac
### Output Screenshot
| Before | After |
|---------|--------|
| **Android**<br> <video src="https://github.com/user-attachments/assets/fda0a962-fdef-425e-9ec6-cfc263af4c53" width="260" height="500"> |**Android**<br> <video src="https://github.com/user-attachments/assets/cb3ed516-2955-46c6-b9aa-4c7ee22207ad" width="260" height="500"> |
| **Windows**<br> <video src="https://github.com/user-attachments/assets/dc8db704-dc67-44ed-8752-0165ed124dd7" width="300" height="600"> | **Windows**<br> <video src="https://github.com/user-attachments/assets/0b14e6c2-b898-4c71-b464-80c33b5bab9e" width="300" height="600"> |
🏁 Report — Final Recommendation
Comparative Analysis — PR #35998
Candidate ranking
| Rank | Candidate | Regression result | Assessment |
|---|---|---|---|
| 1 | try-fix-1 |
✅ PASS — Issue26049 Windows UI tests passed (3/3) |
Best overall. Keeps title observation/update logic in ShellItemHandler, the handler that owns the WinUI NavigationView item view models; avoids the PR's cross-handler extension callback, avoids direct mapper-method bypass, and updates the affected view model instead of rebuilding all menu items for every title change. Self-review findings: []. |
| 2 | pr-plus-reviewer |
Not separately regression-run; based on PR gate ✅ plus reviewer patch | Addresses the expert reviewer's mapper-extensibility finding by restoring a ShellContent.Title mapper entry, while preserving the PR's dynamic ShellContent observation path. Still has weaker ownership boundaries than try-fix-1 because ShellSectionHandler observes title changes and calls into ShellItemHandler. |
| 3 | pr |
✅ PASSED (user-supplied gate) | Functionally fixes the Windows regression, but expert review found a major handler-pattern issue: removing the ShellContent.Title mapper entry can break AppendToMapping/PrependToMapping customization for Title. Also retains less cohesive cross-handler coupling and full menu rebuilds. |
No STEP 5a candidate with failed regression tests ranks above any passing candidate. The only try-fix-N candidate found was try-fix-1, and it passed the targeted Windows regression tests.
Winning candidate
Winner: try-fix-1
try-fix-1 wins because it passed the same Windows regression coverage while producing the cleanest handler ownership model: the Windows Shell item handler that owns the NavigationView menu subscribes to the relevant ShellSection/ShellContent title changes and updates the existing NavigationViewItemViewModel directly. Compared with the PR fix, it avoids direct mapper bypass/cross-handler callback concerns and avoids rebuilding the entire menu just to refresh one title.
Notes on platform scope and CI
All compared implementation candidates are Windows-only. This is acceptable for selecting the best candidate for the requested Windows testing platform, but it does not close the Android half of issue #27494; the test remains excluded on Android with a comment pointing to separate Shell Handler work. Public check-run metadata currently shows failing maui-pr/Build Analysis, but ci-analysis is unavailable and the supplied gate result for the regression scenario is ✅ PASSED.
🧭 Next Steps — alternative fix proposed (try-fix-1)
Automated review — alternative fix proposed
The expert-reviewer evaluation compared the PR fix against automatically generated candidates and selected try-fix-1 as the strongest fix.
Why: try-fix-1 passed the targeted Windows regression tests and has the cleanest ownership model: ShellItemHandler owns the NavigationView menu subscriptions and updates the affected item directly. It avoids the PR fix's mapper-extensibility regression and cross-handler callback/full-menu-rebuild approach.
Please consider applying the candidate diff below (or use it as guidance). Once you push an update, this workflow will re-trigger and re-evaluate.
Candidate diff (try-fix-1)
diff --git a/src/Controls/src/Core/Handlers/Shell/ShellContentHandler.Windows.cs b/src/Controls/src/Core/Handlers/Shell/ShellContentHandler.Windows.cs
index 3ae9eb434f..776e69c383 100644
--- a/src/Controls/src/Core/Handlers/Shell/ShellContentHandler.Windows.cs
+++ b/src/Controls/src/Core/Handlers/Shell/ShellContentHandler.Windows.cs
@@ -7,7 +7,7 @@ namespace Microsoft.Maui.Controls.Handlers
public partial class ShellContentHandler : ElementHandler<ShellContent, FrameworkElement>
{
public static PropertyMapper<ShellContent, ShellContentHandler> Mapper =
- new PropertyMapper<ShellContent, ShellContentHandler>(ElementMapper) { [nameof(ShellContent.Title)] = MapTitle };
+ new PropertyMapper<ShellContent, ShellContentHandler>(ElementMapper);
public static CommandMapper<ShellContent, ShellContentHandler> CommandMapper =
new CommandMapper<ShellContent, ShellContentHandler>(ElementCommandMapper);
@@ -16,14 +16,6 @@ namespace Microsoft.Maui.Controls.Handlers
{
}
- internal static void MapTitle(ShellContentHandler handler, ShellContent item)
- {
- var shellSection = item.Parent as ShellSection;
- var shellItem = shellSection?.Parent as ShellItem;
- var shellItemHandler = shellItem?.Handler as ShellItemHandler;
- shellItemHandler?.UpdateTitle();
- }
-
protected override FrameworkElement CreatePlatformElement()
{
return (VirtualView as IShellContentController).GetOrCreateContent().ToPlatform(MauiContext);
diff --git a/src/Controls/src/Core/Handlers/Shell/ShellItemHandler.Windows.cs b/src/Controls/src/Core/Handlers/Shell/ShellItemHandler.Windows.cs
index fe22429159..37e3ae418e 100644
--- a/src/Controls/src/Core/Handlers/Shell/ShellItemHandler.Windows.cs
+++ b/src/Controls/src/Core/Handlers/Shell/ShellItemHandler.Windows.cs
@@ -29,6 +29,7 @@ namespace Microsoft.Maui.Controls.Handlers
ShellItem? _shellItem;
SearchHandler? _currentSearchHandler;
IShellAppearanceElement? _shellAppearanceElement;
+ readonly HashSet<BaseShellItem> _trackedMenuItems = new();
public ShellItemHandler() : base(Mapper, CommandMapper)
{
@@ -127,13 +128,13 @@ namespace Microsoft.Maui.Controls.Handlers
{
shell.Navigated -= OnShellNavigated;
}
+ }
- foreach (var item in shellItemController.GetItems())
- {
- item.PropertyChanged -= OnShellItemPropertyChanged;
- }
-
+ foreach (var item in _trackedMenuItems)
+ {
+ item.PropertyChanged -= OnShellItemPropertyChanged;
}
+ _trackedMenuItems.Clear();
}
public override void SetVirtualView(Maui.IElement view)
@@ -211,16 +212,39 @@ namespace Microsoft.Maui.Controls.Handlers
internal void MapMenuItems()
{
+ // Unsubscribe from previously tracked items to prevent duplicate subscriptions
+ foreach (var tracked in _trackedMenuItems)
+ {
+ tracked.PropertyChanged -= OnShellItemPropertyChanged;
+ }
+ _trackedMenuItems.Clear();
+
IShellItemController shellItemController = VirtualView;
var items = new List<BaseShellItem>();
foreach (var item in shellItemController.GetItems())
{
item.PropertyChanged += OnShellItemPropertyChanged;
+ _trackedMenuItems.Add(item);
+
+ // Subscribe to all ShellContent children so title changes propagate
+ // whether the section is implicit (TabBar with single content) or explicit
+ foreach (var content in ((IShellSectionController)item).GetItems())
+ {
+ if (_trackedMenuItems.Add(content))
+ {
+ content.PropertyChanged += OnShellItemPropertyChanged;
+ }
+ }
+
if (Routing.IsImplicit(item))
+ {
items.Add(item.CurrentItem);
+ }
else
+ {
items.Add(item);
+ }
}
object? selectedItem = null;
@@ -478,23 +502,44 @@ namespace Microsoft.Maui.Controls.Handlers
return;
}
+ // Check top-level tabs
for (int i = 0; i < _mainLevelTabs.Count; i++)
{
- if (_mainLevelTabs[i].Data != sender)
+ if (_mainLevelTabs[i].Data == sender)
{
- continue;
+ switch (e.PropertyName)
+ {
+ case nameof(BaseShellItem.IsEnabled):
+ _mainLevelTabs[i].IsEnabled = shellItem.IsEnabled;
+ break;
+ case nameof(BaseShellItem.Title):
+ _mainLevelTabs[i].Content = shellItem.Title;
+ break;
+ }
+ return;
}
- switch (e.PropertyName)
+ // Check sub-items (ShellContent within a ShellSection's flyout menu)
+ var menuSource = _mainLevelTabs[i].MenuItemsSource;
+ if (menuSource is not null)
{
- case nameof(BaseShellItem.IsEnabled):
- _mainLevelTabs[i].IsEnabled = shellItem.IsEnabled;
- break;
- case nameof(BaseShellItem.Title):
- _mainLevelTabs[i].Content = shellItem.Title;
- break;
+ foreach (var subItem in menuSource)
+ {
+ if (subItem.Data == sender)
+ {
+ switch (e.PropertyName)
+ {
+ case nameof(BaseShellItem.IsEnabled):
+ subItem.IsEnabled = shellItem.IsEnabled;
+ break;
+ case nameof(BaseShellItem.Title):
+ subItem.Content = shellItem.Title;
+ break;
+ }
+ return;
+ }
+ }
}
- return;
}
}
diff --git a/src/Controls/src/Core/Platform/Windows/Extensions/ShellContentExtensions.cs b/src/Controls/src/Core/Platform/Windows/Extensions/ShellContentExtensions.cs
deleted file mode 100644
index 0a61a52938..0000000000
--- a/src/Controls/src/Core/Platform/Windows/Extensions/ShellContentExtensions.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-using Microsoft.Maui.Controls.Handlers;
-
-namespace Microsoft.Maui.Controls.Platform
-{
- internal static class ShellContentExtensions
- {
- internal static void UpdateParentShellItemTitle(this ShellContent shellContent)
- {
- if (shellContent.Parent is ShellSection shellSection && shellSection.Parent is ShellItem shellItem && shellItem.Handler is ShellItemHandler shellItemHandler)
- {
- shellItemHandler.UpdateTitle();
- }
- }
- }
-}
Root Cause
Runtime scenarios for ShellContent were not properly handled. When ShellContent was added or removed dynamically, its property changes (such as title updates) were not tracked correctly.
Description of Change
Windows: Moved title update handling from ShellContentHandler.Windows to ShellSectionHandler.Windows. This modification ensures that title changes are handled properly for both initial and dynamically added ShellContent items.
Issues Fixed
Fixes #27494
Regarding test case
Added a test case for runtime-added ShellContent title updates in PR #26062 . These tests are applicable to my changes as well
Tested the behavior in the following platforms.
Output Screenshot
Before-fix.mov
After-fix.mov
Before-fix.mp4
After-fix.mp4