Skip to content

Shape.PathForBounds is no longer called for a custom Shape #40129

Done

Description

@mypp74

Description

public class CustomShape : Shape, IShape
{
        public override PathF GetPath()
        {
            ...
        }

        public PathF PathForBounds(Rect bounds)
        {
            ...
        }

        // IShapeWithStroke is internal
        //PathF IShapeWithStroke.PathForBounds(Graphics.Rect viewBounds, bool includeStroke)
        //{
        //}
}

IShapeWithStroke.PathForBounds is now called as a priority. However, since IShapeWithStroke.PathForBounds is internal, a custom Shape cannot implement it; consequently, IShape.PathForBounds is now always ignored for custom Shapes.

FieldShape.zip

Steps to Reproduce

No response

Link to public reproduction project repository

No response

Version with bug

10.0.130

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

10.0.120

Affected platforms

Android, iOS

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

Activity

  1. added
    t/bug
    on Nov 10, 2026
  2. added
    area-drawing
    on Nov 10, 2026
  3. NafeelaNazhir commented on Nov 10, 2026

    @NafeelaNazhir
    Contributor

    This issue has been validated in Visual Studio Code 1.144.1 with .NET MAUI versions 10.0.120 and 10.0.130. It can be reproduced on the Android and iOS platform from 10.0.130 version

    FieldShapeIssue.zip

    10.0.130 version Output 10.0.120 version Output
    ImageImage ImageImage
  4. added
    s/verified
    s/triaged
    i/regression
    on Nov 10, 2026
  5. sheiksyedm commented on Nov 10, 2026

    @sheiksyedm
    Contributor

    @mypp74 For applications staying on .NET MAUI 10.0.130, I suggest the following app-level workaround for the supplied FieldShape used as Border.StrokeShape.

    The regression occurs because the renderer now prefers the internal IShapeWithStroke interface inherited from Shape, bypassing the custom IShape.PathForBounds implementation. A small Border adapter can expose only IShape to the renderer and forward the bounds directly to the existing custom implementation.

    Workaround

    Keep the original FieldShape.cs unchanged. Add this class in the same namespace as FieldShape (FieldShapeIssue in the full reproduction; adjust the namespace for your application):

    using Microsoft.Maui;
    using Microsoft.Maui.Controls;
    using Microsoft.Maui.Graphics;
    
    namespace FieldShapeIssue;
    
    public sealed class FieldShapeBorder : Border, IBorderStroke
    {
        private FieldShape? _source;
        private IShape? _adapter;
    
        IShape? IBorderStroke.Shape
        {
            get
            {
                if (StrokeShape is not FieldShape source)
                {
                    _source = null;
                    _adapter = null;
                    return StrokeShape;
                }
    
                if (!ReferenceEquals(_source, source))
                {
                    _source = source;
                    _adapter = new DirectShape(source);
                }
    
                return _adapter;
            }
        }
    
        // Expose only IShape to the renderer, preserving FieldShape's bounds implementation.
        private sealed class DirectShape : IShape
        {
            private readonly IShape _source;
    
            public DirectShape(IShape source) => _source = source;
    
            public PathF PathForBounds(Rect bounds) => _source.PathForBounds(bounds);
        }
    }

    Replace only the affected <Border> element with <local:FieldShapeBorder>, keeping the existing shape resource, properties, and content:

    <local:FieldShapeBorder Stroke="#512BD4"
                            StrokeThickness="2"
                            StrokeShape="{StaticResource FieldOutline}"
                            Padding="12">
        <Entry Placeholder="Type here" />
    </local:FieldShapeBorder>

    Use the existing xmlns:local mapping for the namespace containing these classes. No MAUI package changes, reflection, or global handler modifications are needed.

    Verification

    I reproduced the issue with the supplied sample on Android and iOS simulators using MAUI 10.0.130. With this adapter, the rounded outline, label gap, and Entry are restored. The rendered application content matches the original 10.0.120 baseline pixel-for-pixel on both platforms, excluding system bars.

    I also compared 7,680 path cases against 10.0.120, including different sizes, label settings, stroke widths, zero Border stroke, and arranged/unarranged shapes. The path operations and coordinates match exactly. Binding-context inheritance, property-change notifications, shape replacement/removal, and built-in shape pass-through were also checked.

    Scope and limitations

    • This workaround targets the reported Border.StrokeShape usage. It does not address standalone Shape rendering or unrelated Clip usage.
    • The original FieldShape remains the Border's logical child, so its existing bindings, notifications, and Shape-specific zero-stroke handling are retained. Other Borders are not changed.
    • I found no visual differences in the tested scenarios, but this is not a blanket guarantee for every application. The adapter cannot implement MAUI's internal shape-version optimization, so additional path recalculations are possible.
  6. added 13 commits that reference this issue on Nov 10, 2026
    815bab9
    0f6279c
    b474cdf
    e0137fd
    24bc545
    5b74120
    fdc4f9b
    191407a
    affde62
    4c7b3fa
    72b3301
    6d7f46d
    286774d
  7. added this to the .NET 11 SR2 milestone on Nov 24, 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-drawingi/regressionplatform/androidplatform/iosregressed-in-10.0.130s/triageds/verifiedt/bug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions