开发者

How to get current position of UIElement within its parent?

开发者 https://www.devze.com 2023-02-05 10:22 出处:网络
Lets say I have this XAML code: <StackPanel Name=\"pan\"> <Button Name=\"but1\" Content=\"Helllo\" />

Lets say I have this XAML code:

<StackPanel Name="pan">
    <Button Name="but1" Content="Helllo" />
    <Button Name="but2" Content="all" />
    <Button Name="but3" Content="开发者_如何学GoWorld" />
</StackPanel>

I my code behind I want to find out what are the coordinates of but2 within pan. How do I do it ?


Something like this:

private Point GetPositionOfBut2() {
   var positionTransform = but2.TransformToAncestor(pan);
   var position = positionTransform.Transform(new Point(0, 0));

   return position;
}
0

精彩评论

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