Sometimes you need to know exactly where an  element is.

Get window relative position


static Point GetPositionInWindow( FrameworkElement element)
{
	GeneralTransform transform = element.TransformToVisual( null);
	return transform.TransformPoint( new Point() /* Represents 0,0 */);
}

Get the bounding rectangle


static Rect GetBoundsInWindow( FrameworkElement element)
{
	GeneralTransform transform = element.TransformToVisual( null);
	return transform.TransformBounds( new Rect( 0, 0, element.ActualWidth, element.ActualHeight));
}

 

 

Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published. Required fields are marked *