DrawingVisual visual = new DrawingVisual(); DrawingContext dc = visual.RenderOpen(); dc.PushClip(new EllipseGeometry(new Point(50, 50), 20, 30)); dc.DrawEllipse(Brushes.Red, null, new Point(50, 50), 20, 30); dc.Close();
DrawingVisual visual = new DrawingVisual(); DrawingContext dc = visual.RenderOpen(); Point[] points = new Point[] { new Point(50, 50), new Point(100, 50), new Point(75, 100) }; dc.PushClip(new PolygonGeometry(points)); dc.DrawRectangle(Brushes.Red, null, new Rect(50, 50, 50, 50)); dc.Close();This example creates a polygon using the PolygonGeometry class and applies it as a clip to the drawing context using the PushClip method. Then, a red rectangle is drawn within the clip region using the DrawRectangle method. Package library: PresentationCore.