Search code examples
c#wpf-controlscoordinatesstackpanel

How do I obtain the client coordinates where a Panel (Canvas, stackpanel, etc) is located in a WPF app?


I need to programatically obtain the client coordinates where a panel (stackpanel for instance) is located. When using the Windows API, a button has a TopLeft and BottomRight coordinate that determines its location within the window in which it resides. How do I obtain those coordinates for a stackpanel in a WPF window ?

Thank you for your help,

John.


Solution

  • You can call TransformToVisual() which gets a GeneralTransform relative to some other element for which you can use your container (frame/ window)

    GeneralTransform gt = stackPanel1.TransformToVisual(parentWindow);         
    Point p = gt.Transform(new Point(0, 0));