What is the WPF equivalent of Windows Forms Region.Xor in the Paint event?

I am trying to move this WinForms code to WPF, but there is no Paint event.

 private void OnPaint(object sender, PaintEventArgs e) { var region = new Region(new Rectangle(0, 0, this.Width, this.Height)); var rectangle = new Rectangle(0, 0, 50, 50); region.Xor(rectangle); e.Graphics.FillRegion(Brushes.Black, region); } 
0
source share
1 answer

WPF does not work like WinForms in terms of graphics. You cannot draw shapes, you must put them in your content.

Geometry should serve as a good replacement for the Region . You can use Geometry.Combine and specify GeometryCombineMode.Xor to copy your drawing code.

RectangleGeometry is how you create rectangles. There are similar classes for other shapes.

To actually display Geometry , put it in a Path that can be used as control content.

+1
source

Source: https://habr.com/ru/post/972985/


All Articles