Articles in this section
Category / Section

How to get bounds of the GridControl in WPF application?

1 min read

GridControl does not have built-in property to get it’s bounds. Please use any one of the following WPF Grid suggestions to get the grid bounds.

Suggestion 1

In order to get the grid’s position on the screen with size, the FrameworkElement.TransformToAncestor method can be used with parent container instance (window).

C#

//parsing the grid as framework element with container
Rect rect = GetBoundingBox(grid as FrameworkElement, this);
private Rect GetBoundingBox(FrameworkElement element, Window containerWindow)
{
    GeneralTransform transform = element.TransformToAncestor(containerWindow);
    //To get the left and top location of the element.
    Point topLeft = transform.Transform(new Point(0, 0));
    //To get the right and bottom point of the element using height and width.
    Point bottomRight = transform.Transform(new Point(element.ActualWidth, element.ActualHeight));
    return new Rect(topLeft, bottomRight);
}

 

Suggestion 2

PointToScreen method of grid and parent container can be used to get the position of GridControl in window by subtracting the window position from control position.

C#

Point position = this.grid.PointToScreen(new Point(0d, 0d));
 Point controlPosition = this.PointToScreen(new Point(0d, 0d));
//To get grid's exact position on the window.
position.X -= controlPosition.X;
position.Y -= controlPosition.Y;

 

Download GridDemo from GitHub

 


Conclusion

I hope you enjoyed learning about how to get bounds of the GridControl in WPF application.

You can refer to our WPF Grid feature tour page to know about its other groundbreaking feature representations. You can also explore our documentation to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied