Find a uielement center in wpf

How to find a UIElement center in wpf?

+6
wpf uielement
source share
2 answers

You can get the absolute position of the control this way

 Point relativePoint = myVisual.TransformToAncestor(rootVisual) .Transform(new Point(0, 0)); 

where myVisual is your control and rootVisual is the parent control (see Get the absolute position of an element in a window in wpf ) so you can find a uielement center like this

 Point pt = new Point(relativePoint.X + myVisual.ActualWidth/2, relativePoint.Y + myVisual.ActualHeight/2); 
+6
source share

Creation of @ArsenMkrt,

 Point center = myVisual.TransformToAncestor(rootVisual).Transform(new Point(myVisual.ActualWidth / 2, myVisual.ActualHeight / 2)); 
0
source share

All Articles