How to get the position of an element in a StackPanel?

后端 未结 1 1798
情深已故
情深已故 2020-12-30 11:27

Say I have a StackPanel that gets dynamically filled with copy, changing the Y position of elements inside it. I have a specific element within that StackPanel that I want t

相关标签:
1条回答
  • 2020-12-30 11:41

    The methods in the link you posted should work fine, provided you call them correctly.

    You need to call them with the correct UIElement - in this case, using element1 to the RootVisual will give you the full position of element1:

    var transform = element1.TransformToVisual(Application.Current.RootVisual as FrameworkElement);        
    Point absolutePosition = transform.Transform(new Point(0, 0));
    
    0 讨论(0)
提交回复
热议问题