Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find the center of a uielement in wpf

Tags:

wpf

uielement

How can I find the center of a UIElement in wpf?

like image 323
np. Avatar asked Oct 09 '09 05:10

np.


1 Answers

You can get absolute position of the control like this

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

where myVisual is your control and rootVisual is the parent control(see Get Absolute Position of element within the window in wpf), so you can find the center of the uielement like this

Point pt = new Point(relativePoint.X + myVisual.ActualWidth/2, relativePoint.Y + myVisual.ActualHeight/2);
like image 175
Arsen Mkrtchyan Avatar answered Oct 16 '22 18:10

Arsen Mkrtchyan