开发者

How to dump all (X, Y) positions of UIElements in a WPF Grid

开发者 https://www.devze.com 2022-12-11 03:39 出处:网络
I would like to know how to iterate through 开发者_运维问答all the elements in a WPF Grid, and then access the absolute positioning values (X, Y) for all of these UIElements.foreach (UIElement child i

I would like to know how to iterate through 开发者_运维问答all the elements in a WPF Grid, and then access the absolute positioning values (X, Y) for all of these UIElements.


foreach (UIElement child in grid.Children)
{
    MatrixTransform t = (MatrixTransform)child.TransformToAncestor(grid);
    Point childLocation = new Point(t.Value.OffsetX, t.Value.OffsetY);
}

Will give you the coordinates of all the direct children relative to the Grid.

0

精彩评论

暂无评论...
验证码 换一张
取 消