Làm cách nào để tìm trung tâm của một số UIElement
trong wpf?Tìm trung tâm của uielement trong wpf
6
A
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ư
Point pt = new Point(relativePoint.X + myVisual.ActualWidth/2, relativePoint.Y + myVisual.ActualHeight/2);
0
Xây dựng tắt @ArsenMkrt,
Point center = myVisual.TransformToAncestor(rootVisual).Transform(new Point(myVisual.ActualWidth/2, myVisual.ActualHeight/2));
Không hoạt động đối với Đường dẫn. Vẫn đang tìm câu trả lời. Cảm ơn –