Hex440bx
Hex440bx

Reputation: 657

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.

Upvotes: 0

Views: 412

Answers (1)

Bala R
Bala R

Reputation: 109017

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));

Upvotes: 1

Related Questions