Question : cant get X/Y

When I rotate an image in silverlight any amount the image left,Top value doesnt change but it must as it rotates in a different position.

I need these values after I rotate an image . This code works but the _x,_y value doesnt change and the image rotates?

        convertAngle = (Angle) * -1
        rt.Angle = convertAngle
   
        rt.CenterX = img2.Width / 2
        rt.CenterY = img2.Height / 1

        img2.RenderTransform = rt

        _x = Canvas.GetLeft(img2)
        _y = newY(Canvas.GetTop(img2))

    End Sub
 

Answer : cant get X/Y

actually this is correct since the X and Y position are transformed and you ll only get the original X and Y position before the transformation.

I use this small code found on msdn (http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/86350f19-6457-470e-bde9-66e8970f7059/) for that kind of things in WPF (it should also work in silverlight):

public Rect GetBounds(FrameworkElement of, FrameworkElement from)
{
// Might throw an exception if of and from are not in the same visual tree
GeneralTransform transform = of.TransformToVisual(from);
return transform.TransformBounds(new Rect(0, 0, of.ActualWidth, of.ActualHeight));
}

you would call it like this:
Rect r=GetBounds(img2,myCanvas);
double x = r.X;
double y = r.Y;

Good luck !
Random Solutions  
 
programming4us programming4us