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)
The position of (X, Y) means the co-ordinate of an element at the top-left point in a document. X represent the horizontal position and Y represent the vertical position. Use element. getBoundingClientRect() property to get the position of an element.
The translateX() function is a 2D transform function used to translate an element along the x-axis. It takes a translation value tx as an argument. This value specifies the amount by which an element is to be translated. The translation value tx is provided either as a <length> or as a percentage .
You can use the CSS position property in combination with the z-index property to overlay an individual div over another div element. The z-index property determines the stacking order for positioned elements (i.e. elements whose position value is one of absolute , fixed , or relative ).
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 TransformToVisual
function (from MSDN):
Returns a transform object that can be used to transform coordinates from the UIElement to the specified object.
TransformToVisual
will yield a GeneralTransform
that 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 the RootVisual
.
var transform = Application.RootVisual.TransformToVisual(myUiElement);
The transform
object is now a general transformation that can be used to transform anything in the same way that myUiElement
was transformed relative to RootVisual
The next step is to transform a point using that transformation.
var myUiElementPosition = transform.Transform(new Point(0,0));
The myUiElementPosition
is now a Point
that has been transformed and should be the position of the UIElement
you'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 the RootVisual
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With