1

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.

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
geejay
  • 5,440
  • 8
  • 50
  • 60

1 Answers1

2
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.

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
Jesper Larsen-Ledet
  • 6,625
  • 3
  • 30
  • 42