1

Lets say I have this XAML code:

<StackPanel Name="pan">
    <Button Name="but1" Content="Helllo" />
    <Button Name="but2" Content="all" />
    <Button Name="but3" Content="World" />
</StackPanel>

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

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
Rasto
  • 17,204
  • 47
  • 154
  • 245

1 Answers1

2

Something like this:

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

   return position;
}
Pavlo Glazkov
  • 20,498
  • 3
  • 58
  • 71