Repository navigation
Description
Description
On Android, when a Border (B) sits inside another Border that has a Shadow, and B's Background brush is mutated in place (SolidColorBrush.Color = ... — which is exactly what an AppThemeBinding inside a style brush does when Application.Current.UserAppTheme changes), the new color is never rendered. All cross-platform state is correct — the brush re-resolves, VisualElement's background-changed proxy fires, the mapper reruns, and even the native MauiDrawable's paint holds the new color — but the on-screen pixels keep the previous color until some unrelated global invalidation (rotation, a system uiMode change, a relayout) redraws the subtree.
Real-world impact: any app implementing an in-app theme switcher via UserAppTheme + the standard XAML theming idiom (implicit styles whose Setter values are SolidColorBrushes with AppThemeBinding colors) shows stale chrome for every themed element nested under a shadowed container. System dark-mode changes mask the bug because the configuration change invalidates everything.
Steps to Reproduce
dotnet new maui, then:
MainPage.xaml
<VerticalStackLayout Padding="24,8" Spacing="8">
<Button Text="Mutate brush color" Clicked="OnMutateClicked" />
<Label Text="1. Plain (control — repaints):" />
<Border x:Name="B1" HeightRequest="40" StrokeThickness="0" StrokeShape="RoundRectangle 12" />
<Label Text="2. Shadowed Border > Grid > Border (STALE):" />
<Border HeightRequest="56" Padding="6" StrokeThickness="0" StrokeShape="RoundRectangle 12">
<Border.Shadow>
<Shadow Brush="Black" Opacity="0.18" Radius="14" Offset="0,3" />
</Border.Shadow>
<Grid>
<Border x:Name="B2" HeightRequest="40" StrokeThickness="0" StrokeShape="RoundRectangle 12" />
</Grid>
</Border>
</VerticalStackLayout>MainPage.xaml.cs
public partial class MainPage : ContentPage
{
// One shared brush — mutated in place, like AppThemeBinding does on UserAppTheme changes.
private readonly SolidColorBrush _sharedBrush = new(Color.FromArgb("#E4EBFD"));
public MainPage()
{
InitializeComponent();
B1.Background = _sharedBrush;
B2.Background = _sharedBrush;
}
private void OnMutateClicked(object? sender, EventArgs e)
=> _sharedBrush.Color = _sharedBrush.Color == Colors.Red ? Colors.Green : Colors.Red;
}Tap the button: B1 turns red, B2 stays #E4EBFD forever (until rotation/uiMode change/any relayout).
Variant matrix (all verified on the same page):
| hierarchy | repaints on mutation? |
|---|---|
plain Border |
✅ |
Border+Shadow > Grid > Border |
❌ stale |
Border+Shadow (opaque solid background) > Grid > Border |
✅ (!) |
Border (no shadow) > Grid > Border |
✅ |
The opaque-background row is the tell for the root cause below: an opaque solid background on the shadowed border takes PlatformWrapperView's fast PlatformShadowDrawable path and the bug disappears; a translucent or absent background takes the bitmap path and the bug appears.
Root cause analysis (verified empirically, hypothesis on the exact flag mechanics)
Three implementation details interact:
-
BorderHandler.Android.CreatePlatformViewsetsLayerType.Hardwareon everyContentViewGroupunconditionally (BorderHandler.Android.cs) — the comment ("We only want to use a hardware layer for the entering view…") suggests this was meant for transition scenarios, not as a permanent layer on every Border. -
With a
Shadowand a non-opaque child background,PlatformWrapperView.drawShadowViaDispatchDrawregenerates its shadow bitmap by drawing the child subtree on a software canvas:super.dispatchDraw(alphaCanvas)(PlatformWrapperView.java). -
That software pass draws the hardware-layered
ContentViewGroupchild and consumes its invalidation state without re-rendering its hardware layer texture. The subsequentsuper.dispatchDraw(canvas)on the hardware canvas then composites the child's stale layer texture — the freshly updatedMauiDrawableis never drawn.
Supporting evidence:
- Explicitly calling
Invalidate()(or evenSetBackgroundColor) on the nested Border's platform view does not repaint it; invalidating the shadowed Border'sContentViewGroup(the hardware-layered ancestor) does — bisected level by level with a cascade of single-view invalidations. - The drawable state was inspected via reflection right after the mutation:
MauiDrawablealready holds the new paint; callback, attach state and layer type are all normal. - [Android] Fix Switch Shadow Does Not Follow Thumb when Toggle On or Off #35623 (10.0.90) fixed the shadow position staleness by invalidating the wrapper in
onDescendantInvalidated, but the wrapper's own invalidate only refreshes the shadow; the child's stale layer texture still composites — this repro is on 10.0.90.
Expected / possible fixes
- Don't set a permanent hardware layer in
BorderHandler(scope it to transitions as the comment implies), or - in
drawShadowViaDispatchDraw, avoid consuming the child's invalidation in the software alpha-extract pass (e.g. draw from the child's layer/RenderNode, or re-invalidate hardware-layered descendants after the extract).
Version with bug
.NET MAUI 10.0.90 (also reproduced on 10.0.80), net10.0-android, Android API 36 emulator (also observed on a physical Android 16 device).
Did you find any workaround?
App/library side: after Application.RequestedThemeChanged, recursively Invalidate() the native subtree (a global sweep repaints everything, which is also why system theme changes appear to work).
Affected platforms
Android (iOS/Windows not verified).
Affected platform versions
Android API 34/36 (emulator and physical device).
I can attach the full runnable repro project as a zip (sources above are the complete delta over dotnet new maui).
Activity
albyrock87 commentedon Aug 10, 2026
Additional findings:
drawShadowViaDispatchDrawsoftware-bake path. Worth checking whether that fix also covers this repro (an in-place brush mutation, where theBackgroundproperty value never changes reference) — the repro above is against 10.0.90, which does not contain it.MauiVersion), even a plainBackgroundre-assignment (setting it tonull) inside the shadowed container leaves the old pixels on screen — e.g. a tab bar's selection highlight ghost persisting on the deselected item after switching tabs. On 10.0.90 the re-assignment case is fixed and only the in-place mutation case remains.TamilarasanSF4853 commentedon Aug 11, 2026
This issue has been validated in Visual Studio Code 1.132.0 with .NET MAUI versions 10.0.0, 10.0.71, 10.0.80 and 10.0.90. It can be reproduced on the Android platform from version 10.0.90.
BorderIssue.zip
10.0.90.mov
10.0.80.mov
Templates: add the maui-nalu-scaffold dotnet new template
Templates: add the maui-nalu-scaffold dotnet new template (#184)
devanathan-vaithiyanathan commentedon Aug 11, 2026
@albyrock87 ,
The issue was resolved by PR #37291.
cc @kubaflo
kubaflo commentedon Aug 11, 2026
Thanks @albyrock87 for reporting it!