views:

356

answers:

1

I have a square 400 x 400 with a plane projection attached to it

<Rectangle  x:Name="Ground" Width="400" Height="400" Stroke="Black" VerticalAlignment="Bottom" Canvas.Left="60" Canvas.Top="50" >
       <Rectangle.Fill>
        <ImageBrush ImageSource="_images/grass.jpg"/>
       </Rectangle.Fill>
       <Rectangle.Projection>
        <PlaneProjection x:Name="GroundPlaneProjection" CenterOfRotationZ="0" GlobalOffsetX="0" GlobalOffsetY="0" GlobalOffsetZ="0" LocalOffsetX="0" LocalOffsetY="0" LocalOffsetZ="0" RotationX="120" RotationY="-40" RotationZ="25"/>
       </Rectangle.Projection>
      </Rectangle>

How would i determine the bounds of the transformed square so that objects placed on it won't be out of bounds?

+1  A: 

You can convert between the coordinate spaces of different elements by using the TransformToVisual method on UIElement. This will give you a transform object, which you can use to transform points in the coordinate space of one element to the coordinate space of another.

This should help you achieve what you are attempting to do.

KeithMahoney
Thanks for the reply. I have tried this to no avail before posting, but again i may be doing it wrong. GeneralTransform transform = control.TransformToVisual(Ground); Point coordinates = transform.Transform(new Point(Ground.Margin.Left + Ground.Width,Ground.Margin.Top + Ground.Height)); so in theory that should give me a Point that is at the bottom right corner of the transformed Rectangle, but it doesn't. I am wondering if I need to transform the rectangle to the canvas the contains the rectangle. I will try this and see.
James Helms
If you want to get the bottom right corner of "Ground" relative to some panel (say "LayoutRoot"), you would do:var transform = Ground.TransformToVisual(LayoutRoot);var point = transform.Transform(new Point(Ground.Width, Ground.Height);
KeithMahoney