I have a UIElement that has various transformations performed on it (scale and translate).
Is there a way to get the UIElement’s position after transformation? I tried GetValue(Canvas.TopProperty) but it doesn’t change from what it was loaded as.
I must be missing something obvious but not sure what. (I’m using silverlight)
It is a little bit unintuitive to do this, but it can be done. It is a two step process. First, what you want to use the
TransformToVisualfunction (from MSDN):TransformToVisualwill yield aGeneralTransformthat will perform the transformation from any UIElement to any other UIElement (given that they both exist in the same visual tree). It sounds like what you want is the transformation from theRootVisual.The
transformobject is now a general transformation that can be used to transform anything in the same way thatmyUiElementwas transformed relative toRootVisualThe next step is to transform a point using that transformation.
The
myUiElementPositionis now aPointthat has been transformed and should be the position of theUIElementyou’re looking for.new Point(0,0)is used because I assume you want to have the position given relative to the top left corner of theRootVisual.