Skip to content

Resolve the Shell appearance from the top non-modal page - #39902

Merged
kubaflo merged 2 commits into
dotnet:candidate/11.0.1xx-sr2from
MykhailoDav:fix-18409-shell-appearance-modal
Nov 11, 2026
Merged

kubaflo merged 2 commits into
dotnet:candidate/11.0.1xx-sr2from
MykhailoDav:fix-18409-shell-appearance-modal

Conversation

@MykhailoDav

Copy link
Copy Markdown
Contributor

Description of Change

When a modal page is pushed at startup, the Shell toolbar gets the default dark color instead of the colors set on the Shell, and stays wrong after the modal closes (on Android and Windows, which drive the toolbar from the resolved ShellAppearance).

Root cause

GetAppearanceForPivot walks up from the pivot's presented page to collect the Shell.* appearance values. For a ShellSection pivot, WalkToPage used IShellSectionController.PresentedPage, which returns the top modal page while a modal is open. Modal pages are parented to the Window, not the Shell, so the walk immediately left the Shell tree, found nothing and returned null — and the toolbar fell back to the default colors.

Fix

WalkToPage now resolves the ShellSection to the top page of its own navigation stack — exactly what PresentedPage returns when no modal is open — so appearance resolution gives the same result whether or not a modal is sitting on top.

Tests

ShellAppearanceTests.AppearanceIsResolvedWhileAModalPageIsOpen: sets Shell.BackgroundColor, pushes a modal page, then registers an appearance observer for the current section.

Without fix With fix
main (2f3276c) Fails: the observer gets a null appearance Passes; Controls.Core.UnitTests 6734 passed (the one failure is a pre-existing decimal-separator locale test that fails on main on this machine too)

Issues Fixed

Fixes #18409

GetAppearanceForPivot walks up from the pivot's presented page to collect the
Shell appearance values. IShellSectionController.PresentedPage returns the top
modal page when a modal is open, and modal pages are parented to the Window,
not the Shell, so the walk found nothing and the toolbar fell back to the
default dark color. That's why pushing a modal page at startup left the Shell
with the wrong theme on Android and Windows.

WalkToPage now uses the top page of the ShellSection's own navigation stack,
which is what PresentedPage returns when no modal is open.

Fixes dotnet#18409
@github-actions

github-actions Bot commented Nov 4, 2026

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 -- 39902

Or

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

@dotnet-policy-service dotnet-policy-service Bot added the community ✨ Community Contribution label Nov 4, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

@azure-pipelines

This comment has been minimized.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

@kubaflo

This comment has been minimized.

@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 Nov 4, 2026
@azure-pipelines

This comment has been minimized.

@github-actions github-actions Bot 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.

Expert Review — 0 findings

Reviewed commit cf456b9.

@MauiBot

MauiBot commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator

PR Test Gate

@MykhailoDav — existing-test verification for commit cf456b93.

Result PASSED Platform Android Commit cf456b93


🧪 Gate analysis — click to expand

✅ Passed. The selected verification satisfied the gate's passing conditions. Unmatched, skipped, or inconclusive groups are not passing evidence.

🧪 Unit tests
Test group Without fix With fix
ShellAppearanceTests ✅ Failed as expected (78s) ✅ Passed (49s)
Execution log excerpts

Without fix ShellAppearanceTests

     at Microsoft.Maui.Controls.Core.UnitTests.ShellAppearanceTests.AppearanceIsResolvedWhileAModalPageIsOpen() in /_/src/Controls/tests/Core.UnitTests/ShellAppearanceTests.cs:line 666

With fix ShellAppearanceTests

ptyChildSolidBrushReplacesInheritedBackgroundWhenPopulated [< 1 ms]
  Passed EmptyChildGradientReplacesInheritedBackgroundWhenPopulated(initiallyEmpty: True) [1 ms]
  Passed EmptyChildGradientReplacesInheritedBackgroundWhenPopulated(initiallyEmpty: False) [< 1 ms]
  Passed EqualAppearanceObserversHaveIndependentBrushSubscriptions [< 1 ms]
  Passed EffectiveTabBarBackground_UsesBackgroundBrush [1 ms]
  Passed TabBarBackgroundColorDoesNotSuppressNavigationSolidBrushInvalidation [< 1 ms]
[xUnit.net 00:00:04.43]   Finished:    Microsoft.Maui.Controls.Core.UnitTests
  Passed EffectiveTabBarBackground_BackgroundBrushWinsOverBackgroundColor [1 ms]
  Passed SharedSolidBrushDoesNotRetainShellOrAppearanceObservers [33 ms]
  Passed SolidColorBrushChangesUpdateAppearanceAndDetachWhenReplacedOrRemoved [1 ms]
  Passed EffectiveTabBarBackground_NullWhenNothingSet [< 1 ms]
  Passed SharedEmptyBackgroundIsObservedOnlyOnce [< 1 ms]
  Passed OneAppearanceObserverTracksBrushesForEachPivot [< 1 ms]
  Passed AppearanceIsResolvedWhileAModalPageIsOpen [28 ms]
  Passed EffectiveTabBarBackground_UsesTabBarBackgroundColor [1 ms]
Test Run Successful.
Total tests: 35
     Passed: 35
 Total time: 5.6257 Seconds

PR head: cf456b93.

Without-fix baseline: 2f3276c3.

@MauiBot MauiBot added s/agent-gate-passed AI verified tests catch the bug (fail without fix, pass with fix) and removed s/agent-review-in-progress AI review is currently running for this PR labels Nov 5, 2026
@kubaflo

This comment has been minimized.

@kubaflo
kubaflo changed the base branch from main to candidate/11.0.1xx-sr2 November 11, 2026 00:38
@kubaflo
kubaflo merged commit daa01a9 into dotnet:candidate/11.0.1xx-sr2 Nov 11, 2026
141 of 185 checks passed
kubaflo added a commit that referenced this pull request Nov 11, 2026
### Description of Change

When a modal page is pushed at startup, the Shell toolbar gets the
default dark color instead of the colors set on the Shell, and stays
wrong after the modal closes (on Android and Windows, which drive the
toolbar from the resolved `ShellAppearance`).

**Root cause**

`GetAppearanceForPivot` walks up from the pivot's presented page to
collect the `Shell.*` appearance values. For a `ShellSection` pivot,
`WalkToPage` used `IShellSectionController.PresentedPage`, which returns
the top modal page while a modal is open. Modal pages are parented to
the `Window`, not the Shell, so the walk immediately left the Shell
tree, found nothing and returned null — and the toolbar fell back to the
default colors.

**Fix**

`WalkToPage` now resolves the `ShellSection` to the top page of its own
navigation stack — exactly what `PresentedPage` returns when no modal is
open — so appearance resolution gives the same result whether or not a
modal is sitting on top.

**Tests**

`ShellAppearanceTests.AppearanceIsResolvedWhileAModalPageIsOpen`: sets
`Shell.BackgroundColor`, pushes a modal page, then registers an
appearance observer for the current section.

| | Without fix | With fix |
|---|---|---|
| `main` (2f3276c) | Fails: the observer gets a null appearance |
Passes; Controls.Core.UnitTests 6734 passed (the one failure is a
pre-existing decimal-separator locale test that fails on `main` on this
machine too) |

### Issues Fixed

Fixes #18409

Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Nov 13, 2026
### Description of Change

When a modal page is pushed at startup, the Shell toolbar gets the
default dark color instead of the colors set on the Shell, and stays
wrong after the modal closes (on Android and Windows, which drive the
toolbar from the resolved `ShellAppearance`).

**Root cause**

`GetAppearanceForPivot` walks up from the pivot's presented page to
collect the `Shell.*` appearance values. For a `ShellSection` pivot,
`WalkToPage` used `IShellSectionController.PresentedPage`, which returns
the top modal page while a modal is open. Modal pages are parented to
the `Window`, not the Shell, so the walk immediately left the Shell
tree, found nothing and returned null — and the toolbar fell back to the
default colors.

**Fix**

`WalkToPage` now resolves the `ShellSection` to the top page of its own
navigation stack — exactly what `PresentedPage` returns when no modal is
open — so appearance resolution gives the same result whether or not a
modal is sitting on top.

**Tests**

`ShellAppearanceTests.AppearanceIsResolvedWhileAModalPageIsOpen`: sets
`Shell.BackgroundColor`, pushes a modal page, then registers an
appearance observer for the current section.

| | Without fix | With fix |
|---|---|---|
| `main` (2f3276c) | Fails: the observer gets a null appearance |
Passes; Controls.Core.UnitTests 6734 passed (the one failure is a
pre-existing decimal-separator locale test that fails on `main` on this
machine too) |

### Issues Fixed

Fixes #18409

Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Nov 16, 2026
### Description of Change

When a modal page is pushed at startup, the Shell toolbar gets the
default dark color instead of the colors set on the Shell, and stays
wrong after the modal closes (on Android and Windows, which drive the
toolbar from the resolved `ShellAppearance`).

**Root cause**

`GetAppearanceForPivot` walks up from the pivot's presented page to
collect the `Shell.*` appearance values. For a `ShellSection` pivot,
`WalkToPage` used `IShellSectionController.PresentedPage`, which returns
the top modal page while a modal is open. Modal pages are parented to
the `Window`, not the Shell, so the walk immediately left the Shell
tree, found nothing and returned null — and the toolbar fell back to the
default colors.

**Fix**

`WalkToPage` now resolves the `ShellSection` to the top page of its own
navigation stack — exactly what `PresentedPage` returns when no modal is
open — so appearance resolution gives the same result whether or not a
modal is sitting on top.

**Tests**

`ShellAppearanceTests.AppearanceIsResolvedWhileAModalPageIsOpen`: sets
`Shell.BackgroundColor`, pushes a modal page, then registers an
appearance observer for the current section.

| | Without fix | With fix |
|---|---|---|
| `main` (2f3276c) | Fails: the observer gets a null appearance |
Passes; Controls.Core.UnitTests 6734 passed (the one failure is a
pre-existing decimal-separator locale test that fails on `main` on this
machine too) |

### Issues Fixed

Fixes #18409

Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Nov 16, 2026
### Description of Change

When a modal page is pushed at startup, the Shell toolbar gets the
default dark color instead of the colors set on the Shell, and stays
wrong after the modal closes (on Android and Windows, which drive the
toolbar from the resolved `ShellAppearance`).

**Root cause**

`GetAppearanceForPivot` walks up from the pivot's presented page to
collect the `Shell.*` appearance values. For a `ShellSection` pivot,
`WalkToPage` used `IShellSectionController.PresentedPage`, which returns
the top modal page while a modal is open. Modal pages are parented to
the `Window`, not the Shell, so the walk immediately left the Shell
tree, found nothing and returned null — and the toolbar fell back to the
default colors.

**Fix**

`WalkToPage` now resolves the `ShellSection` to the top page of its own
navigation stack — exactly what `PresentedPage` returns when no modal is
open — so appearance resolution gives the same result whether or not a
modal is sitting on top.

**Tests**

`ShellAppearanceTests.AppearanceIsResolvedWhileAModalPageIsOpen`: sets
`Shell.BackgroundColor`, pushes a modal page, then registers an
appearance observer for the current section.

| | Without fix | With fix |
|---|---|---|
| `main` (2f3276c) | Fails: the observer gets a null appearance |
Passes; Controls.Core.UnitTests 6734 passed (the one failure is a
pre-existing decimal-separator locale test that fails on `main` on this
machine too) |

### Issues Fixed

Fixes #18409

Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Nov 17, 2026
### Description of Change

When a modal page is pushed at startup, the Shell toolbar gets the
default dark color instead of the colors set on the Shell, and stays
wrong after the modal closes (on Android and Windows, which drive the
toolbar from the resolved `ShellAppearance`).

**Root cause**

`GetAppearanceForPivot` walks up from the pivot's presented page to
collect the `Shell.*` appearance values. For a `ShellSection` pivot,
`WalkToPage` used `IShellSectionController.PresentedPage`, which returns
the top modal page while a modal is open. Modal pages are parented to
the `Window`, not the Shell, so the walk immediately left the Shell
tree, found nothing and returned null — and the toolbar fell back to the
default colors.

**Fix**

`WalkToPage` now resolves the `ShellSection` to the top page of its own
navigation stack — exactly what `PresentedPage` returns when no modal is
open — so appearance resolution gives the same result whether or not a
modal is sitting on top.

**Tests**

`ShellAppearanceTests.AppearanceIsResolvedWhileAModalPageIsOpen`: sets
`Shell.BackgroundColor`, pushes a modal page, then registers an
appearance observer for the current section.

| | Without fix | With fix |
|---|---|---|
| `main` (2f3276c) | Fails: the observer gets a null appearance |
Passes; Controls.Core.UnitTests 6734 passed (the one failure is a
pre-existing decimal-separator locale test that fails on `main` on this
machine too) |

### Issues Fixed

Fixes #18409

Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Nov 17, 2026
…dal page is open (#40333)

### Description of Change

On Android, if the app theme changes while a modal page is open over a
Shell, the Shell navigation bar falls back to the default colors
(`#2C3E50` in light, `#1B3147` in dark). It stays that way after the
modal is closed, even when `Shell.BackgroundColor` uses an
`AppThemeBinding`.

`Shell.OnRequestedThemeChanged` calls `AppearanceChanged(CurrentPage,
false)`. While a modal is open, `CurrentPage` is the modal page. Modal
pages are parented to the Window, so `GetAppearanceForPivot` walks up
from the modal, never reaches the Shell and returns null.
`UpdateToolbarAppearanceFeatures` then writes the default colors into
`Shell.Toolbar`. `Application` raises `RequestedThemeChanged` after the
`AppThemeBinding` values have already updated, so these defaults are the
last thing written. Nothing recalculates the appearance when the modal
is popped.

The fix has two parts in `Shell.cs`:

1. `OnRequestedThemeChanged` passes `GetCurrentShellPage()` instead of
`CurrentPage`. That helper already exists for "the visible page without
the modal stack", and `GetEffectiveValue` uses it. Without a modal both
return the same page, so only the modal case changes.
2. `WalkToPage` for a `ShellSection` uses the top page of the section's
own stack instead of `PresentedPage`. This hunk is the same change as
#39902 (#18409), copied byte for byte from its merge commit daa01a9.
#39902 is merged into `candidate/11.0.1xx-sr2` but isn't on `net11` yet.
With only the first change, the theme change reaches Android's
`ShellSectionHandler` observer, whose pivot is the section, and
`WalkToPage` sends it to the modal again, so the defaults come back. If
this PR is retargeted to a branch that already has #39902, that hunk is
identical to what's there and only the one-line change is new.

### Tests


`ShellAppearanceTests.ThemeChangeWhileAModalPageIsOpenKeepsTheToolbarAppearance`
(Controls.Core.UnitTests) sets an `AppThemeBinding` background
(Red/Blue) on a Shell, adds an observer on the ShellSection the way
Android's `ShellSectionHandler` does, pushes a modal and switches
`UserAppTheme` to Dark. It checks that `Shell.Toolbar.BarBackground` and
the observer's appearance are both Blue.

| `Shell.cs` | Result |
|---|---|
| without the fix | fails: `Expected: [Color: Red=0, Green=0, Blue=1,
Alpha=1] Actual: null` |
| only the `OnRequestedThemeChanged` change | fails, same message |
| only the `WalkToPage` change | fails, same message |
| both | passes |

Controls.Core.UnitTests with the fix: 6734 passed, 1 failed, 30 skipped.
The failure is
`TwoWayBindingToNullableDoublePropertyWithEmptyStringBecomesNull`, which
also fails on clean `net11` on my machine because of a decimal-comma
locale. Shell tests (`FullyQualifiedName~Shell`): 565 of 565 passed.

**Before / after** (sandbox app, Android emulator API 37): the bar is
red in the light theme and blue with a yellow title in the dark theme.
Each clip opens a modal, switches the emulator to dark mode with `adb
shell cmd uimode night yes` and closes the modal.

| Before: after closing the modal the bar is the default `#1B3147` |
After: the bar is blue with the yellow title |
|---|---|
|
![before](https://raw.githubusercontent.com/MykhailoDav/maui/media-pr-2026-11-12/40240-before.png)
|
![after](https://raw.githubusercontent.com/MykhailoDav/maui/media-pr-2026-11-12/40240-after.png)
|

Full clips:
[before.mp4](https://raw.githubusercontent.com/MykhailoDav/maui/media-pr-2026-11-12/40240-before.mp4)
·
[after.mp4](https://raw.githubusercontent.com/MykhailoDav/maui/media-pr-2026-11-12/40240-after.mp4).
There's also a [clip with only the first
change](https://raw.githubusercontent.com/MykhailoDav/maui/media-pr-2026-11-12/40240-after-oneliner-only.mp4),
where the bar still ends up `#1B3147`.

I only recorded the light-to-dark direction, with Material 3 off (the
default). iOS and Windows go through the same `Shell.cs` code, but I
didn't run them.

### Issues Fixed

Fixes #40240

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
kubaflo added a commit that referenced this pull request Nov 18, 2026
### Description of Change

When a modal page is pushed at startup, the Shell toolbar gets the
default dark color instead of the colors set on the Shell, and stays
wrong after the modal closes (on Android and Windows, which drive the
toolbar from the resolved `ShellAppearance`).

**Root cause**

`GetAppearanceForPivot` walks up from the pivot's presented page to
collect the `Shell.*` appearance values. For a `ShellSection` pivot,
`WalkToPage` used `IShellSectionController.PresentedPage`, which returns
the top modal page while a modal is open. Modal pages are parented to
the `Window`, not the Shell, so the walk immediately left the Shell
tree, found nothing and returned null — and the toolbar fell back to the
default colors.

**Fix**

`WalkToPage` now resolves the `ShellSection` to the top page of its own
navigation stack — exactly what `PresentedPage` returns when no modal is
open — so appearance resolution gives the same result whether or not a
modal is sitting on top.

**Tests**

`ShellAppearanceTests.AppearanceIsResolvedWhileAModalPageIsOpen`: sets
`Shell.BackgroundColor`, pushes a modal page, then registers an
appearance observer for the current section.

| | Without fix | With fix |
|---|---|---|
| `main` (2f3276c) | Fails: the observer gets a null appearance |
Passes; Controls.Core.UnitTests 6734 passed (the one failure is a
pre-existing decimal-separator locale test that fails on `main` on this
machine too) |

### Issues Fixed

Fixes #18409

Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Nov 18, 2026
…dal page is open (#40333)

### Description of Change

On Android, if the app theme changes while a modal page is open over a
Shell, the Shell navigation bar falls back to the default colors
(`#2C3E50` in light, `#1B3147` in dark). It stays that way after the
modal is closed, even when `Shell.BackgroundColor` uses an
`AppThemeBinding`.

`Shell.OnRequestedThemeChanged` calls `AppearanceChanged(CurrentPage,
false)`. While a modal is open, `CurrentPage` is the modal page. Modal
pages are parented to the Window, so `GetAppearanceForPivot` walks up
from the modal, never reaches the Shell and returns null.
`UpdateToolbarAppearanceFeatures` then writes the default colors into
`Shell.Toolbar`. `Application` raises `RequestedThemeChanged` after the
`AppThemeBinding` values have already updated, so these defaults are the
last thing written. Nothing recalculates the appearance when the modal
is popped.

The fix has two parts in `Shell.cs`:

1. `OnRequestedThemeChanged` passes `GetCurrentShellPage()` instead of
`CurrentPage`. That helper already exists for "the visible page without
the modal stack", and `GetEffectiveValue` uses it. Without a modal both
return the same page, so only the modal case changes.
2. `WalkToPage` for a `ShellSection` uses the top page of the section's
own stack instead of `PresentedPage`. This hunk is the same change as
#39902 (#18409), copied byte for byte from its merge commit daa01a9.
#39902 is merged into `candidate/11.0.1xx-sr2` but isn't on `net11` yet.
With only the first change, the theme change reaches Android's
`ShellSectionHandler` observer, whose pivot is the section, and
`WalkToPage` sends it to the modal again, so the defaults come back. If
this PR is retargeted to a branch that already has #39902, that hunk is
identical to what's there and only the one-line change is new.

### Tests


`ShellAppearanceTests.ThemeChangeWhileAModalPageIsOpenKeepsTheToolbarAppearance`
(Controls.Core.UnitTests) sets an `AppThemeBinding` background
(Red/Blue) on a Shell, adds an observer on the ShellSection the way
Android's `ShellSectionHandler` does, pushes a modal and switches
`UserAppTheme` to Dark. It checks that `Shell.Toolbar.BarBackground` and
the observer's appearance are both Blue.

| `Shell.cs` | Result |
|---|---|
| without the fix | fails: `Expected: [Color: Red=0, Green=0, Blue=1,
Alpha=1] Actual: null` |
| only the `OnRequestedThemeChanged` change | fails, same message |
| only the `WalkToPage` change | fails, same message |
| both | passes |

Controls.Core.UnitTests with the fix: 6734 passed, 1 failed, 30 skipped.
The failure is
`TwoWayBindingToNullableDoublePropertyWithEmptyStringBecomesNull`, which
also fails on clean `net11` on my machine because of a decimal-comma
locale. Shell tests (`FullyQualifiedName~Shell`): 565 of 565 passed.

**Before / after** (sandbox app, Android emulator API 37): the bar is
red in the light theme and blue with a yellow title in the dark theme.
Each clip opens a modal, switches the emulator to dark mode with `adb
shell cmd uimode night yes` and closes the modal.

| Before: after closing the modal the bar is the default `#1B3147` |
After: the bar is blue with the yellow title |
|---|---|
|
![before](https://raw.githubusercontent.com/MykhailoDav/maui/media-pr-2026-11-12/40240-before.png)
|
![after](https://raw.githubusercontent.com/MykhailoDav/maui/media-pr-2026-11-12/40240-after.png)
|

Full clips:
[before.mp4](https://raw.githubusercontent.com/MykhailoDav/maui/media-pr-2026-11-12/40240-before.mp4)
·
[after.mp4](https://raw.githubusercontent.com/MykhailoDav/maui/media-pr-2026-11-12/40240-after.mp4).
There's also a [clip with only the first
change](https://raw.githubusercontent.com/MykhailoDav/maui/media-pr-2026-11-12/40240-after-oneliner-only.mp4),
where the bar still ends up `#1B3147`.

I only recorded the light-to-dark direction, with Material 3 off (the
default). iOS and Windows go through the same `Shell.cs` code, but I
didn't run them.

### Issues Fixed

Fixes #40240

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
kubaflo added a commit that referenced this pull request Nov 18, 2026
### Description of Change

When a modal page is pushed at startup, the Shell toolbar gets the
default dark color instead of the colors set on the Shell, and stays
wrong after the modal closes (on Android and Windows, which drive the
toolbar from the resolved `ShellAppearance`).

**Root cause**

`GetAppearanceForPivot` walks up from the pivot's presented page to
collect the `Shell.*` appearance values. For a `ShellSection` pivot,
`WalkToPage` used `IShellSectionController.PresentedPage`, which returns
the top modal page while a modal is open. Modal pages are parented to
the `Window`, not the Shell, so the walk immediately left the Shell
tree, found nothing and returned null — and the toolbar fell back to the
default colors.

**Fix**

`WalkToPage` now resolves the `ShellSection` to the top page of its own
navigation stack — exactly what `PresentedPage` returns when no modal is
open — so appearance resolution gives the same result whether or not a
modal is sitting on top.

**Tests**

`ShellAppearanceTests.AppearanceIsResolvedWhileAModalPageIsOpen`: sets
`Shell.BackgroundColor`, pushes a modal page, then registers an
appearance observer for the current section.

| | Without fix | With fix |
|---|---|---|
| `main` (2f3276c) | Fails: the observer gets a null appearance |
Passes; Controls.Core.UnitTests 6734 passed (the one failure is a
pre-existing decimal-separator locale test that fails on `main` on this
machine too) |

### Issues Fixed

Fixes #18409

Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Nov 18, 2026
…dal page is open (#40333)

### Description of Change

On Android, if the app theme changes while a modal page is open over a
Shell, the Shell navigation bar falls back to the default colors
(`#2C3E50` in light, `#1B3147` in dark). It stays that way after the
modal is closed, even when `Shell.BackgroundColor` uses an
`AppThemeBinding`.

`Shell.OnRequestedThemeChanged` calls `AppearanceChanged(CurrentPage,
false)`. While a modal is open, `CurrentPage` is the modal page. Modal
pages are parented to the Window, so `GetAppearanceForPivot` walks up
from the modal, never reaches the Shell and returns null.
`UpdateToolbarAppearanceFeatures` then writes the default colors into
`Shell.Toolbar`. `Application` raises `RequestedThemeChanged` after the
`AppThemeBinding` values have already updated, so these defaults are the
last thing written. Nothing recalculates the appearance when the modal
is popped.

The fix has two parts in `Shell.cs`:

1. `OnRequestedThemeChanged` passes `GetCurrentShellPage()` instead of
`CurrentPage`. That helper already exists for "the visible page without
the modal stack", and `GetEffectiveValue` uses it. Without a modal both
return the same page, so only the modal case changes.
2. `WalkToPage` for a `ShellSection` uses the top page of the section's
own stack instead of `PresentedPage`. This hunk is the same change as
#39902 (#18409), copied byte for byte from its merge commit daa01a9.
#39902 is merged into `candidate/11.0.1xx-sr2` but isn't on `net11` yet.
With only the first change, the theme change reaches Android's
`ShellSectionHandler` observer, whose pivot is the section, and
`WalkToPage` sends it to the modal again, so the defaults come back. If
this PR is retargeted to a branch that already has #39902, that hunk is
identical to what's there and only the one-line change is new.

### Tests


`ShellAppearanceTests.ThemeChangeWhileAModalPageIsOpenKeepsTheToolbarAppearance`
(Controls.Core.UnitTests) sets an `AppThemeBinding` background
(Red/Blue) on a Shell, adds an observer on the ShellSection the way
Android's `ShellSectionHandler` does, pushes a modal and switches
`UserAppTheme` to Dark. It checks that `Shell.Toolbar.BarBackground` and
the observer's appearance are both Blue.

| `Shell.cs` | Result |
|---|---|
| without the fix | fails: `Expected: [Color: Red=0, Green=0, Blue=1,
Alpha=1] Actual: null` |
| only the `OnRequestedThemeChanged` change | fails, same message |
| only the `WalkToPage` change | fails, same message |
| both | passes |

Controls.Core.UnitTests with the fix: 6734 passed, 1 failed, 30 skipped.
The failure is
`TwoWayBindingToNullableDoublePropertyWithEmptyStringBecomesNull`, which
also fails on clean `net11` on my machine because of a decimal-comma
locale. Shell tests (`FullyQualifiedName~Shell`): 565 of 565 passed.

**Before / after** (sandbox app, Android emulator API 37): the bar is
red in the light theme and blue with a yellow title in the dark theme.
Each clip opens a modal, switches the emulator to dark mode with `adb
shell cmd uimode night yes` and closes the modal.

| Before: after closing the modal the bar is the default `#1B3147` |
After: the bar is blue with the yellow title |
|---|---|
|
![before](https://raw.githubusercontent.com/MykhailoDav/maui/media-pr-2026-11-12/40240-before.png)
|
![after](https://raw.githubusercontent.com/MykhailoDav/maui/media-pr-2026-11-12/40240-after.png)
|

Full clips:
[before.mp4](https://raw.githubusercontent.com/MykhailoDav/maui/media-pr-2026-11-12/40240-before.mp4)
·
[after.mp4](https://raw.githubusercontent.com/MykhailoDav/maui/media-pr-2026-11-12/40240-after.mp4).
There's also a [clip with only the first
change](https://raw.githubusercontent.com/MykhailoDav/maui/media-pr-2026-11-12/40240-after-oneliner-only.mp4),
where the bar still ends up `#1B3147`.

I only recorded the light-to-dark direction, with Material 3 off (the
default). iOS and Windows go through the same `Shell.cs` code, but I
didn't run them.

### Issues Fixed

Fixes #40240

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
kubaflo added a commit that referenced this pull request Nov 18, 2026
### Description of Change

When a modal page is pushed at startup, the Shell toolbar gets the
default dark color instead of the colors set on the Shell, and stays
wrong after the modal closes (on Android and Windows, which drive the
toolbar from the resolved `ShellAppearance`).

**Root cause**

`GetAppearanceForPivot` walks up from the pivot's presented page to
collect the `Shell.*` appearance values. For a `ShellSection` pivot,
`WalkToPage` used `IShellSectionController.PresentedPage`, which returns
the top modal page while a modal is open. Modal pages are parented to
the `Window`, not the Shell, so the walk immediately left the Shell
tree, found nothing and returned null — and the toolbar fell back to the
default colors.

**Fix**

`WalkToPage` now resolves the `ShellSection` to the top page of its own
navigation stack — exactly what `PresentedPage` returns when no modal is
open — so appearance resolution gives the same result whether or not a
modal is sitting on top.

**Tests**

`ShellAppearanceTests.AppearanceIsResolvedWhileAModalPageIsOpen`: sets
`Shell.BackgroundColor`, pushes a modal page, then registers an
appearance observer for the current section.

| | Without fix | With fix |
|---|---|---|
| `main` (2f3276c) | Fails: the observer gets a null appearance |
Passes; Controls.Core.UnitTests 6734 passed (the one failure is a
pre-existing decimal-separator locale test that fails on `main` on this
machine too) |

### Issues Fixed

Fixes #18409

Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Nov 18, 2026
…dal page is open (#40333)

### Description of Change

On Android, if the app theme changes while a modal page is open over a
Shell, the Shell navigation bar falls back to the default colors
(`#2C3E50` in light, `#1B3147` in dark). It stays that way after the
modal is closed, even when `Shell.BackgroundColor` uses an
`AppThemeBinding`.

`Shell.OnRequestedThemeChanged` calls `AppearanceChanged(CurrentPage,
false)`. While a modal is open, `CurrentPage` is the modal page. Modal
pages are parented to the Window, so `GetAppearanceForPivot` walks up
from the modal, never reaches the Shell and returns null.
`UpdateToolbarAppearanceFeatures` then writes the default colors into
`Shell.Toolbar`. `Application` raises `RequestedThemeChanged` after the
`AppThemeBinding` values have already updated, so these defaults are the
last thing written. Nothing recalculates the appearance when the modal
is popped.

The fix has two parts in `Shell.cs`:

1. `OnRequestedThemeChanged` passes `GetCurrentShellPage()` instead of
`CurrentPage`. That helper already exists for "the visible page without
the modal stack", and `GetEffectiveValue` uses it. Without a modal both
return the same page, so only the modal case changes.
2. `WalkToPage` for a `ShellSection` uses the top page of the section's
own stack instead of `PresentedPage`. This hunk is the same change as
#39902 (#18409), copied byte for byte from its merge commit daa01a9.
#39902 is merged into `candidate/11.0.1xx-sr2` but isn't on `net11` yet.
With only the first change, the theme change reaches Android's
`ShellSectionHandler` observer, whose pivot is the section, and
`WalkToPage` sends it to the modal again, so the defaults come back. If
this PR is retargeted to a branch that already has #39902, that hunk is
identical to what's there and only the one-line change is new.

### Tests


`ShellAppearanceTests.ThemeChangeWhileAModalPageIsOpenKeepsTheToolbarAppearance`
(Controls.Core.UnitTests) sets an `AppThemeBinding` background
(Red/Blue) on a Shell, adds an observer on the ShellSection the way
Android's `ShellSectionHandler` does, pushes a modal and switches
`UserAppTheme` to Dark. It checks that `Shell.Toolbar.BarBackground` and
the observer's appearance are both Blue.

| `Shell.cs` | Result |
|---|---|
| without the fix | fails: `Expected: [Color: Red=0, Green=0, Blue=1,
Alpha=1] Actual: null` |
| only the `OnRequestedThemeChanged` change | fails, same message |
| only the `WalkToPage` change | fails, same message |
| both | passes |

Controls.Core.UnitTests with the fix: 6734 passed, 1 failed, 30 skipped.
The failure is
`TwoWayBindingToNullableDoublePropertyWithEmptyStringBecomesNull`, which
also fails on clean `net11` on my machine because of a decimal-comma
locale. Shell tests (`FullyQualifiedName~Shell`): 565 of 565 passed.

**Before / after** (sandbox app, Android emulator API 37): the bar is
red in the light theme and blue with a yellow title in the dark theme.
Each clip opens a modal, switches the emulator to dark mode with `adb
shell cmd uimode night yes` and closes the modal.

| Before: after closing the modal the bar is the default `#1B3147` |
After: the bar is blue with the yellow title |
|---|---|
|
![before](https://raw.githubusercontent.com/MykhailoDav/maui/media-pr-2026-11-12/40240-before.png)
|
![after](https://raw.githubusercontent.com/MykhailoDav/maui/media-pr-2026-11-12/40240-after.png)
|

Full clips:
[before.mp4](https://raw.githubusercontent.com/MykhailoDav/maui/media-pr-2026-11-12/40240-before.mp4)
·
[after.mp4](https://raw.githubusercontent.com/MykhailoDav/maui/media-pr-2026-11-12/40240-after.mp4).
There's also a [clip with only the first
change](https://raw.githubusercontent.com/MykhailoDav/maui/media-pr-2026-11-12/40240-after-oneliner-only.mp4),
where the bar still ends up `#1B3147`.

I only recorded the light-to-dark direction, with Material 3 off (the
default). iOS and Windows go through the same `Shell.cs` code, but I
didn't run them.

### Issues Fixed

Fixes #40240

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
kubaflo added a commit that referenced this pull request Nov 19, 2026
### Description of Change

When a modal page is pushed at startup, the Shell toolbar gets the
default dark color instead of the colors set on the Shell, and stays
wrong after the modal closes (on Android and Windows, which drive the
toolbar from the resolved `ShellAppearance`).

**Root cause**

`GetAppearanceForPivot` walks up from the pivot's presented page to
collect the `Shell.*` appearance values. For a `ShellSection` pivot,
`WalkToPage` used `IShellSectionController.PresentedPage`, which returns
the top modal page while a modal is open. Modal pages are parented to
the `Window`, not the Shell, so the walk immediately left the Shell
tree, found nothing and returned null — and the toolbar fell back to the
default colors.

**Fix**

`WalkToPage` now resolves the `ShellSection` to the top page of its own
navigation stack — exactly what `PresentedPage` returns when no modal is
open — so appearance resolution gives the same result whether or not a
modal is sitting on top.

**Tests**

`ShellAppearanceTests.AppearanceIsResolvedWhileAModalPageIsOpen`: sets
`Shell.BackgroundColor`, pushes a modal page, then registers an
appearance observer for the current section.

| | Without fix | With fix |
|---|---|---|
| `main` (2f3276c) | Fails: the observer gets a null appearance |
Passes; Controls.Core.UnitTests 6734 passed (the one failure is a
pre-existing decimal-separator locale test that fails on `main` on this
machine too) |

### Issues Fixed

Fixes #18409

Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Nov 19, 2026
…dal page is open (#40333)

### Description of Change

On Android, if the app theme changes while a modal page is open over a
Shell, the Shell navigation bar falls back to the default colors
(`#2C3E50` in light, `#1B3147` in dark). It stays that way after the
modal is closed, even when `Shell.BackgroundColor` uses an
`AppThemeBinding`.

`Shell.OnRequestedThemeChanged` calls `AppearanceChanged(CurrentPage,
false)`. While a modal is open, `CurrentPage` is the modal page. Modal
pages are parented to the Window, so `GetAppearanceForPivot` walks up
from the modal, never reaches the Shell and returns null.
`UpdateToolbarAppearanceFeatures` then writes the default colors into
`Shell.Toolbar`. `Application` raises `RequestedThemeChanged` after the
`AppThemeBinding` values have already updated, so these defaults are the
last thing written. Nothing recalculates the appearance when the modal
is popped.

The fix has two parts in `Shell.cs`:

1. `OnRequestedThemeChanged` passes `GetCurrentShellPage()` instead of
`CurrentPage`. That helper already exists for "the visible page without
the modal stack", and `GetEffectiveValue` uses it. Without a modal both
return the same page, so only the modal case changes.
2. `WalkToPage` for a `ShellSection` uses the top page of the section's
own stack instead of `PresentedPage`. This hunk is the same change as
#39902 (#18409), copied byte for byte from its merge commit daa01a9.
#39902 is merged into `candidate/11.0.1xx-sr2` but isn't on `net11` yet.
With only the first change, the theme change reaches Android's
`ShellSectionHandler` observer, whose pivot is the section, and
`WalkToPage` sends it to the modal again, so the defaults come back. If
this PR is retargeted to a branch that already has #39902, that hunk is
identical to what's there and only the one-line change is new.

### Tests


`ShellAppearanceTests.ThemeChangeWhileAModalPageIsOpenKeepsTheToolbarAppearance`
(Controls.Core.UnitTests) sets an `AppThemeBinding` background
(Red/Blue) on a Shell, adds an observer on the ShellSection the way
Android's `ShellSectionHandler` does, pushes a modal and switches
`UserAppTheme` to Dark. It checks that `Shell.Toolbar.BarBackground` and
the observer's appearance are both Blue.

| `Shell.cs` | Result |
|---|---|
| without the fix | fails: `Expected: [Color: Red=0, Green=0, Blue=1,
Alpha=1] Actual: null` |
| only the `OnRequestedThemeChanged` change | fails, same message |
| only the `WalkToPage` change | fails, same message |
| both | passes |

Controls.Core.UnitTests with the fix: 6734 passed, 1 failed, 30 skipped.
The failure is
`TwoWayBindingToNullableDoublePropertyWithEmptyStringBecomesNull`, which
also fails on clean `net11` on my machine because of a decimal-comma
locale. Shell tests (`FullyQualifiedName~Shell`): 565 of 565 passed.

**Before / after** (sandbox app, Android emulator API 37): the bar is
red in the light theme and blue with a yellow title in the dark theme.
Each clip opens a modal, switches the emulator to dark mode with `adb
shell cmd uimode night yes` and closes the modal.

| Before: after closing the modal the bar is the default `#1B3147` |
After: the bar is blue with the yellow title |
|---|---|
|
![before](https://raw.githubusercontent.com/MykhailoDav/maui/media-pr-2026-11-12/40240-before.png)
|
![after](https://raw.githubusercontent.com/MykhailoDav/maui/media-pr-2026-11-12/40240-after.png)
|

Full clips:
[before.mp4](https://raw.githubusercontent.com/MykhailoDav/maui/media-pr-2026-11-12/40240-before.mp4)
·
[after.mp4](https://raw.githubusercontent.com/MykhailoDav/maui/media-pr-2026-11-12/40240-after.mp4).
There's also a [clip with only the first
change](https://raw.githubusercontent.com/MykhailoDav/maui/media-pr-2026-11-12/40240-after-oneliner-only.mp4),
where the bar still ends up `#1B3147`.

I only recorded the light-to-dark direction, with Material 3 off (the
default). iOS and Windows go through the same `Shell.cs` code, but I
didn't run them.

### Issues Fixed

Fixes #40240

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
kubaflo added a commit that referenced this pull request Nov 22, 2026
### Description of Change

When a modal page is pushed at startup, the Shell toolbar gets the
default dark color instead of the colors set on the Shell, and stays
wrong after the modal closes (on Android and Windows, which drive the
toolbar from the resolved `ShellAppearance`).

**Root cause**

`GetAppearanceForPivot` walks up from the pivot's presented page to
collect the `Shell.*` appearance values. For a `ShellSection` pivot,
`WalkToPage` used `IShellSectionController.PresentedPage`, which returns
the top modal page while a modal is open. Modal pages are parented to
the `Window`, not the Shell, so the walk immediately left the Shell
tree, found nothing and returned null — and the toolbar fell back to the
default colors.

**Fix**

`WalkToPage` now resolves the `ShellSection` to the top page of its own
navigation stack — exactly what `PresentedPage` returns when no modal is
open — so appearance resolution gives the same result whether or not a
modal is sitting on top.

**Tests**

`ShellAppearanceTests.AppearanceIsResolvedWhileAModalPageIsOpen`: sets
`Shell.BackgroundColor`, pushes a modal page, then registers an
appearance observer for the current section.

| | Without fix | With fix |
|---|---|---|
| `main` (2f3276c) | Fails: the observer gets a null appearance |
Passes; Controls.Core.UnitTests 6734 passed (the one failure is a
pre-existing decimal-separator locale test that fails on `main` on this
machine too) |

### Issues Fixed

Fixes #18409

Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Nov 22, 2026
…dal page is open (#40333)

### Description of Change

On Android, if the app theme changes while a modal page is open over a
Shell, the Shell navigation bar falls back to the default colors
(`#2C3E50` in light, `#1B3147` in dark). It stays that way after the
modal is closed, even when `Shell.BackgroundColor` uses an
`AppThemeBinding`.

`Shell.OnRequestedThemeChanged` calls `AppearanceChanged(CurrentPage,
false)`. While a modal is open, `CurrentPage` is the modal page. Modal
pages are parented to the Window, so `GetAppearanceForPivot` walks up
from the modal, never reaches the Shell and returns null.
`UpdateToolbarAppearanceFeatures` then writes the default colors into
`Shell.Toolbar`. `Application` raises `RequestedThemeChanged` after the
`AppThemeBinding` values have already updated, so these defaults are the
last thing written. Nothing recalculates the appearance when the modal
is popped.

The fix has two parts in `Shell.cs`:

1. `OnRequestedThemeChanged` passes `GetCurrentShellPage()` instead of
`CurrentPage`. That helper already exists for "the visible page without
the modal stack", and `GetEffectiveValue` uses it. Without a modal both
return the same page, so only the modal case changes.
2. `WalkToPage` for a `ShellSection` uses the top page of the section's
own stack instead of `PresentedPage`. This hunk is the same change as
#39902 (#18409), copied byte for byte from its merge commit daa01a9.
#39902 is merged into `candidate/11.0.1xx-sr2` but isn't on `net11` yet.
With only the first change, the theme change reaches Android's
`ShellSectionHandler` observer, whose pivot is the section, and
`WalkToPage` sends it to the modal again, so the defaults come back. If
this PR is retargeted to a branch that already has #39902, that hunk is
identical to what's there and only the one-line change is new.

### Tests


`ShellAppearanceTests.ThemeChangeWhileAModalPageIsOpenKeepsTheToolbarAppearance`
(Controls.Core.UnitTests) sets an `AppThemeBinding` background
(Red/Blue) on a Shell, adds an observer on the ShellSection the way
Android's `ShellSectionHandler` does, pushes a modal and switches
`UserAppTheme` to Dark. It checks that `Shell.Toolbar.BarBackground` and
the observer's appearance are both Blue.

| `Shell.cs` | Result |
|---|---|
| without the fix | fails: `Expected: [Color: Red=0, Green=0, Blue=1,
Alpha=1] Actual: null` |
| only the `OnRequestedThemeChanged` change | fails, same message |
| only the `WalkToPage` change | fails, same message |
| both | passes |

Controls.Core.UnitTests with the fix: 6734 passed, 1 failed, 30 skipped.
The failure is
`TwoWayBindingToNullableDoublePropertyWithEmptyStringBecomesNull`, which
also fails on clean `net11` on my machine because of a decimal-comma
locale. Shell tests (`FullyQualifiedName~Shell`): 565 of 565 passed.

**Before / after** (sandbox app, Android emulator API 37): the bar is
red in the light theme and blue with a yellow title in the dark theme.
Each clip opens a modal, switches the emulator to dark mode with `adb
shell cmd uimode night yes` and closes the modal.

| Before: after closing the modal the bar is the default `#1B3147` |
After: the bar is blue with the yellow title |
|---|---|
|
![before](https://raw.githubusercontent.com/MykhailoDav/maui/media-pr-2026-11-12/40240-before.png)
|
![after](https://raw.githubusercontent.com/MykhailoDav/maui/media-pr-2026-11-12/40240-after.png)
|

Full clips:
[before.mp4](https://raw.githubusercontent.com/MykhailoDav/maui/media-pr-2026-11-12/40240-before.mp4)
·
[after.mp4](https://raw.githubusercontent.com/MykhailoDav/maui/media-pr-2026-11-12/40240-after.mp4).
There's also a [clip with only the first
change](https://raw.githubusercontent.com/MykhailoDav/maui/media-pr-2026-11-12/40240-after-oneliner-only.mp4),
where the bar still ends up `#1B3147`.

I only recorded the light-to-dark direction, with Material 3 off (the
default). iOS and Windows go through the same `Shell.cs` code, but I
didn't run them.

### Issues Fixed

Fixes #40240

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
kubaflo added a commit that referenced this pull request Nov 23, 2026
### Description of Change

When a modal page is pushed at startup, the Shell toolbar gets the
default dark color instead of the colors set on the Shell, and stays
wrong after the modal closes (on Android and Windows, which drive the
toolbar from the resolved `ShellAppearance`).

**Root cause**

`GetAppearanceForPivot` walks up from the pivot's presented page to
collect the `Shell.*` appearance values. For a `ShellSection` pivot,
`WalkToPage` used `IShellSectionController.PresentedPage`, which returns
the top modal page while a modal is open. Modal pages are parented to
the `Window`, not the Shell, so the walk immediately left the Shell
tree, found nothing and returned null — and the toolbar fell back to the
default colors.

**Fix**

`WalkToPage` now resolves the `ShellSection` to the top page of its own
navigation stack — exactly what `PresentedPage` returns when no modal is
open — so appearance resolution gives the same result whether or not a
modal is sitting on top.

**Tests**

`ShellAppearanceTests.AppearanceIsResolvedWhileAModalPageIsOpen`: sets
`Shell.BackgroundColor`, pushes a modal page, then registers an
appearance observer for the current section.

| | Without fix | With fix |
|---|---|---|
| `main` (2f3276c) | Fails: the observer gets a null appearance |
Passes; Controls.Core.UnitTests 6734 passed (the one failure is a
pre-existing decimal-separator locale test that fails on `main` on this
machine too) |

### Issues Fixed

Fixes #18409

Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Nov 23, 2026
…dal page is open (#40333)

### Description of Change

On Android, if the app theme changes while a modal page is open over a
Shell, the Shell navigation bar falls back to the default colors
(`#2C3E50` in light, `#1B3147` in dark). It stays that way after the
modal is closed, even when `Shell.BackgroundColor` uses an
`AppThemeBinding`.

`Shell.OnRequestedThemeChanged` calls `AppearanceChanged(CurrentPage,
false)`. While a modal is open, `CurrentPage` is the modal page. Modal
pages are parented to the Window, so `GetAppearanceForPivot` walks up
from the modal, never reaches the Shell and returns null.
`UpdateToolbarAppearanceFeatures` then writes the default colors into
`Shell.Toolbar`. `Application` raises `RequestedThemeChanged` after the
`AppThemeBinding` values have already updated, so these defaults are the
last thing written. Nothing recalculates the appearance when the modal
is popped.

The fix has two parts in `Shell.cs`:

1. `OnRequestedThemeChanged` passes `GetCurrentShellPage()` instead of
`CurrentPage`. That helper already exists for "the visible page without
the modal stack", and `GetEffectiveValue` uses it. Without a modal both
return the same page, so only the modal case changes.
2. `WalkToPage` for a `ShellSection` uses the top page of the section's
own stack instead of `PresentedPage`. This hunk is the same change as
#39902 (#18409), copied byte for byte from its merge commit daa01a9.
#39902 is merged into `candidate/11.0.1xx-sr2` but isn't on `net11` yet.
With only the first change, the theme change reaches Android's
`ShellSectionHandler` observer, whose pivot is the section, and
`WalkToPage` sends it to the modal again, so the defaults come back. If
this PR is retargeted to a branch that already has #39902, that hunk is
identical to what's there and only the one-line change is new.

### Tests


`ShellAppearanceTests.ThemeChangeWhileAModalPageIsOpenKeepsTheToolbarAppearance`
(Controls.Core.UnitTests) sets an `AppThemeBinding` background
(Red/Blue) on a Shell, adds an observer on the ShellSection the way
Android's `ShellSectionHandler` does, pushes a modal and switches
`UserAppTheme` to Dark. It checks that `Shell.Toolbar.BarBackground` and
the observer's appearance are both Blue.

| `Shell.cs` | Result |
|---|---|
| without the fix | fails: `Expected: [Color: Red=0, Green=0, Blue=1,
Alpha=1] Actual: null` |
| only the `OnRequestedThemeChanged` change | fails, same message |
| only the `WalkToPage` change | fails, same message |
| both | passes |

Controls.Core.UnitTests with the fix: 6734 passed, 1 failed, 30 skipped.
The failure is
`TwoWayBindingToNullableDoublePropertyWithEmptyStringBecomesNull`, which
also fails on clean `net11` on my machine because of a decimal-comma
locale. Shell tests (`FullyQualifiedName~Shell`): 565 of 565 passed.

**Before / after** (sandbox app, Android emulator API 37): the bar is
red in the light theme and blue with a yellow title in the dark theme.
Each clip opens a modal, switches the emulator to dark mode with `adb
shell cmd uimode night yes` and closes the modal.

| Before: after closing the modal the bar is the default `#1B3147` |
After: the bar is blue with the yellow title |
|---|---|
|
![before](https://raw.githubusercontent.com/MykhailoDav/maui/media-pr-2026-11-12/40240-before.png)
|
![after](https://raw.githubusercontent.com/MykhailoDav/maui/media-pr-2026-11-12/40240-after.png)
|

Full clips:
[before.mp4](https://raw.githubusercontent.com/MykhailoDav/maui/media-pr-2026-11-12/40240-before.mp4)
·
[after.mp4](https://raw.githubusercontent.com/MykhailoDav/maui/media-pr-2026-11-12/40240-after.mp4).
There's also a [clip with only the first
change](https://raw.githubusercontent.com/MykhailoDav/maui/media-pr-2026-11-12/40240-after-oneliner-only.mp4),
where the bar still ends up `#1B3147`.

I only recorded the light-to-dark direction, with Material 3 off (the
default). iOS and Windows go through the same `Shell.cs` code, but I
didn't run them.

### Issues Fixed

Fixes #40240

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
@kubaflo kubaflo added this to the .NET 11 SR2 milestone Nov 24, 2026
KarthikRajaKalaimani pushed a commit to KarthikRajaKalaimani/maui that referenced this pull request Nov 26, 2026
### Description of Change

When a modal page is pushed at startup, the Shell toolbar gets the
default dark color instead of the colors set on the Shell, and stays
wrong after the modal closes (on Android and Windows, which drive the
toolbar from the resolved `ShellAppearance`).

**Root cause**

`GetAppearanceForPivot` walks up from the pivot's presented page to
collect the `Shell.*` appearance values. For a `ShellSection` pivot,
`WalkToPage` used `IShellSectionController.PresentedPage`, which returns
the top modal page while a modal is open. Modal pages are parented to
the `Window`, not the Shell, so the walk immediately left the Shell
tree, found nothing and returned null — and the toolbar fell back to the
default colors.

**Fix**

`WalkToPage` now resolves the `ShellSection` to the top page of its own
navigation stack — exactly what `PresentedPage` returns when no modal is
open — so appearance resolution gives the same result whether or not a
modal is sitting on top.

**Tests**

`ShellAppearanceTests.AppearanceIsResolvedWhileAModalPageIsOpen`: sets
`Shell.BackgroundColor`, pushes a modal page, then registers an
appearance observer for the current section.

| | Without fix | With fix |
|---|---|---|
| `main` (2f3276c) | Fails: the observer gets a null appearance |
Passes; Controls.Core.UnitTests 6734 passed (the one failure is a
pre-existing decimal-separator locale test that fails on `main` on this
machine too) |

### Issues Fixed

Fixes dotnet#18409

Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
KarthikRajaKalaimani pushed a commit to KarthikRajaKalaimani/maui that referenced this pull request Nov 26, 2026
…dal page is open (dotnet#40333)

### Description of Change

On Android, if the app theme changes while a modal page is open over a
Shell, the Shell navigation bar falls back to the default colors
(`#2C3E50` in light, `#1B3147` in dark). It stays that way after the
modal is closed, even when `Shell.BackgroundColor` uses an
`AppThemeBinding`.

`Shell.OnRequestedThemeChanged` calls `AppearanceChanged(CurrentPage,
false)`. While a modal is open, `CurrentPage` is the modal page. Modal
pages are parented to the Window, so `GetAppearanceForPivot` walks up
from the modal, never reaches the Shell and returns null.
`UpdateToolbarAppearanceFeatures` then writes the default colors into
`Shell.Toolbar`. `Application` raises `RequestedThemeChanged` after the
`AppThemeBinding` values have already updated, so these defaults are the
last thing written. Nothing recalculates the appearance when the modal
is popped.

The fix has two parts in `Shell.cs`:

1. `OnRequestedThemeChanged` passes `GetCurrentShellPage()` instead of
`CurrentPage`. That helper already exists for "the visible page without
the modal stack", and `GetEffectiveValue` uses it. Without a modal both
return the same page, so only the modal case changes.
2. `WalkToPage` for a `ShellSection` uses the top page of the section's
own stack instead of `PresentedPage`. This hunk is the same change as
dotnet#39902 (dotnet#18409), copied byte for byte from its merge commit daa01a9.
dotnet#39902 is merged into `candidate/11.0.1xx-sr2` but isn't on `net11` yet.
With only the first change, the theme change reaches Android's
`ShellSectionHandler` observer, whose pivot is the section, and
`WalkToPage` sends it to the modal again, so the defaults come back. If
this PR is retargeted to a branch that already has dotnet#39902, that hunk is
identical to what's there and only the one-line change is new.

### Tests


`ShellAppearanceTests.ThemeChangeWhileAModalPageIsOpenKeepsTheToolbarAppearance`
(Controls.Core.UnitTests) sets an `AppThemeBinding` background
(Red/Blue) on a Shell, adds an observer on the ShellSection the way
Android's `ShellSectionHandler` does, pushes a modal and switches
`UserAppTheme` to Dark. It checks that `Shell.Toolbar.BarBackground` and
the observer's appearance are both Blue.

| `Shell.cs` | Result |
|---|---|
| without the fix | fails: `Expected: [Color: Red=0, Green=0, Blue=1,
Alpha=1] Actual: null` |
| only the `OnRequestedThemeChanged` change | fails, same message |
| only the `WalkToPage` change | fails, same message |
| both | passes |

Controls.Core.UnitTests with the fix: 6734 passed, 1 failed, 30 skipped.
The failure is
`TwoWayBindingToNullableDoublePropertyWithEmptyStringBecomesNull`, which
also fails on clean `net11` on my machine because of a decimal-comma
locale. Shell tests (`FullyQualifiedName~Shell`): 565 of 565 passed.

**Before / after** (sandbox app, Android emulator API 37): the bar is
red in the light theme and blue with a yellow title in the dark theme.
Each clip opens a modal, switches the emulator to dark mode with `adb
shell cmd uimode night yes` and closes the modal.

| Before: after closing the modal the bar is the default `#1B3147` |
After: the bar is blue with the yellow title |
|---|---|
|
![before](https://raw.githubusercontent.com/MykhailoDav/maui/media-pr-2026-11-12/40240-before.png)
|
![after](https://raw.githubusercontent.com/MykhailoDav/maui/media-pr-2026-11-12/40240-after.png)
|

Full clips:
[before.mp4](https://raw.githubusercontent.com/MykhailoDav/maui/media-pr-2026-11-12/40240-before.mp4)
·
[after.mp4](https://raw.githubusercontent.com/MykhailoDav/maui/media-pr-2026-11-12/40240-after.mp4).
There's also a [clip with only the first
change](https://raw.githubusercontent.com/MykhailoDav/maui/media-pr-2026-11-12/40240-after-oneliner-only.mp4),
where the bar still ends up `#1B3147`.

I only recorded the light-to-dark direction, with Material 3 off (the
default). iOS and Windows go through the same `Shell.cs` code, but I
didn't run them.

### Issues Fixed

Fixes dotnet#40240

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — cf456b93 Deployed Nov 4, 2026 by MykhailoDav via conclusion #2703
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community ✨ Community Contribution s/agent-gate-passed AI verified tests catch the bug (fail without fix, pass with fix)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Windows][Android] Shell theme incorrect when pushing a modal page at startup

3 participants