Fredou
Fredou

Reputation: 20120

is there a build-in method to convert from Rectangle to RectangleGeometry

I have been looking around I can't seem to find a build-in way to do the "conversion", I just need a confirmation before I do it.

Do I have to manually create the Rect object based on the Rectangle proprieties and pass it in the RectangleGeometry constructor?

(I hope there is a build-in way...)

Upvotes: 0

Views: 737

Answers (2)

Clemens
Clemens

Reputation: 128067

A Rectangle only has (Actual)Width and (Actual)Height properties, while (in addition to Width and Height) a Rect also has X and Y properties.

You may however directly get a RectangleGeometry from a Rectangle's RenderedGeometry property:

var rectangleGeometry = rectangle.RenderedGeometry as RectangleGeometry;

Upvotes: 0

mm8
mm8

Reputation: 169280

A Rectangle is a FrameworkElement/Visual that may be displayed in the visual tree and Rect is a simple struct, i.e. they aren't similar objects and there is no straightforward conversion: https://social.msdn.microsoft.com/Forums/en-US/f5feb8b2-0555-403e-a1f9-967ccf970c7a/how-can-i-transform-rectangle-to-rect-and-vice-versa?forum=winappswithcsharp

So yes, you should manually create the Rect object based on the size of the Rectangle element.

Upvotes: 1

Related Questions