开发者

How to get current position of UIElement within its parent?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜