2009-10-09 14 views

Trả lời

6

Bạn có thể lấy vị trí tuyệt đối của sự kiểm soát như

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

nơi myVisual là kiểm soát của bạn và rootVisual là phụ huynh kiểm soát (xem Get Absolute Position of element within the window in wpf), vì vậy bạn có thể tìm thấy trung tâm của UIElement như

này
Point pt = new Point(relativePoint.X + myVisual.ActualWidth/2, relativePoint.Y + myVisual.ActualHeight/2); 
+3

Không hoạt động đối với Đường dẫn. Vẫn đang tìm câu trả lời. Cảm ơn –

0

Xây dựng tắt @ArsenMkrt,

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