开发者

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

开发者 https://www.devze.com 2023-03-04 18:49 出处:网络
I need to programatically obta开发者_StackOverflowin the client coordinates where a panel (stackpanel for instance) is located. When using the Windows API, a button has a TopLeft and BottomRight coord

I need to programatically obta开发者_StackOverflowin 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.


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

精彩评论

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

关注公众号