Search code examples
c#wpfellipsebrush

Brush only parts of an Ellipse in WPF


I'm having trouble to find the best way to draw the below shape. I'm using the below code to draw an Ellipse on visual layer.

But how can I only brush the quarters? I think it can be done using LinearGradientBrush or RadialGradientBrush but I don't know how use it.

var cntrpoint = space.FlipYAxis(x2, y2);
dc.DrawEllipse(Brushes.Transparent, pen, cntrpoint, 30, 30);

enter image description here


Solution

  • Like this:

    var geometry = new GeometryGroup();
    geometry.Children.Add(new RectangleGeometry(new Rect(1, 0, 1, 1)));
    geometry.Children.Add(new RectangleGeometry(new Rect(0, 1, 1, 1)));
    var drawing = new GeometryDrawing(Brushes.Black, null, geometry);
    var brush = new DrawingBrush(drawing);
    
    dc.DrawEllipse(brush, pen, cntrpoint, 30, 30);