Find control position on canvas

前端 未结 2 1332
挽巷
挽巷 2021-01-04 02:55

I have a Canvas which contains a few Textblocks and I need to find the top and left corner points that were assigned in the XAML Document. How can

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-04 03:34

    Elegant solution

    foreach (FrameworkElement fe in Canvas.Children)
             Thickness margin = fe.Margin;
    
    MessageBox.Show("Left: " + margin.Left + "Top: " + margin.Top);
    

提交回复
热议问题