Skip to content

[Android] Border nested inside a shadowed Border never repaints when its Background brush mutates in place (breaks AppThemeBinding brushes on UserAppTheme changes) #37289

Closed

Description

@albyrock87

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:

  1. BorderHandler.Android.CreatePlatformView sets LayerType.Hardware on every ContentViewGroup unconditionally (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.

  2. With a Shadow and a non-opaque child background, PlatformWrapperView.drawShadowViaDispatchDraw regenerates its shadow bitmap by drawing the child subtree on a software canvas: super.dispatchDraw(alphaCanvas) (PlatformWrapperView.java).

  3. That software pass draws the hardware-layered ContentViewGroup child and consumes its invalidation state without re-rendering its hardware layer texture. The subsequent super.dispatchDraw(canvas) on the hardware canvas then composites the child's stale layer texture — the freshly updated MauiDrawable is never drawn.

Supporting evidence:

  • Explicitly calling Invalidate() (or even SetBackgroundColor) on the nested Border's platform view does not repaint it; invalidating the shadowed Border's ContentViewGroup (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: MauiDrawable already 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

  1. albyrock87 commented on Aug 10, 2026

    @albyrock87
    ContributorAuthor

    Additional findings:

    • Likely related to Fix Border with Shadow breaking descendant BackgroundColor updates on Android #36988 ("[WIP] Fix Border with Shadow breaking descendant BackgroundColor updates on Android", commit 5d428e5, currently unreleased): it targets the same drawShadowViaDispatchDraw software-bake path. Worth checking whether that fix also covers this repro (an in-place brush mutation, where the Background property value never changes reference) — the repro above is against 10.0.90, which does not contain it.
    • On older patch levels the symptom is broader: with 10.0.20 (the workload's bundled default when an app doesn't pin MauiVersion), even a plain Background re-assignment (setting it to null) 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.
    • Version note: I verified the in-place mutation staleness on 10.0.90 (emulator API 36 and a physical Android 16 device); I have not re-verified 10.0.80 in isolation, so please read "Version with bug" as 10.0.90.
  2. added
    s/verified
    s/triaged
    and removed
    s/verified
    s/triaged
    on Aug 11, 2026
  3. TamilarasanSF4853 commented on Aug 11, 2026

    @TamilarasanSF4853
    Contributor

    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
  4. added
    s/verified
    s/triaged
    i/regression
    on Aug 11, 2026
  5. added
    partner/syncfusion
    on Aug 11, 2026
  6. devanathan-vaithiyanathan commented on Aug 11, 2026

    @devanathan-vaithiyanathan
    Contributor

    @albyrock87 ,
    The issue was resolved by PR #37291.

    cc @kubaflo

  7. kubaflo commented on Aug 11, 2026

    @kubaflo
    Contributor

    Thanks @albyrock87 for reporting it!

  8. locked and limited conversation to collaborators on Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-controls-borderi/regressionpartner/syncfusionplatform/androidregressed-in-10.0.90s/triageds/verified

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions