Skip to content

DrawRectangle in DrawingGroup's DrawingContext does not support rounded corners #20525

@jroessel

Description

@jroessel

Describe the bug

var drawing = new DrawingGroup();
using(var ctx = drawing.Open()) {
  ctx.DrawRectangle(Brushes.Green, Pens.Red, new RoundedRect(new Rect(0, 0, 100, 50), 25));
}

results in

Image

This is because DrawingGroup's context implementation simply creates a rectangle geometry without any radii in

protected override void DrawRectangleCore(IBrush? brush, IPen? pen, RoundedRect rrect, BoxShadows boxShadows = default)
{
// Instantiate the geometry
var geometry = _platformRenderInterface.CreateRectangleGeometry(rrect.Rect);
// Add Drawing to the Drawing graph
AddNewGeometryDrawing(brush, pen, new PlatformGeometry(geometry));
}

As a workaround, DrawGeometry with a RectangleGeometry can be used.

To Reproduce

Create a DrawingGroup, call DrawingGroup.Open to obtain a DrawingContext and call DrawRectangle with a RoundedRect (or one of the other overloads that allows to specify corner radii).

Expected behavior

The specified corner radii should be honored.

Avalonia version

11.3.10

OS

Windows

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions