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;
}
精彩评论