WPF Rect Transform

I am trying to apply RotateTransformto an object Rectwith the following code.

Rect transformed = this.Rectangle;
transformed.Transform(this.rotateTransform.Value);
DrawingVisual visual = new DrawingVisual();
DrawingContext context = visual.RenderOpen();
context.DrawRectangle(null, new Pen(Brushes.Blue, 2), transformed);
context.Close();
canvas.Children.Add(visual);

but the rectangle does not rotate. However, when I click the transform on DrawingContext, as in the following code, the rectangle is converted correctly.

Rect transformed = this.Rectangle;
DrawingVisual visual = new DrawingVisual();
DrawingContext context = visual.RenderOpen();
context.PushTransform(this.rotateTransform);
context.DrawRectangle(null, new Pen(Brushes.Blue, 2), transformed);
context.Pop();
context.Close();
canvas.Children.Add(visual);

Is there a way to convert Rect, as in the first code snippet using a function Rect.Transform(Matrix)?

+3
source share
1 answer

True, because your rotation is not a multiple of 90deg. Transform on Rect makes it parallel to the x and y axis!

  • The first case displays a modified rectangle that does not rotate, and the desire syou - it seems that after the box it produces a box.
  • , - " ",
+2

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


All Articles