【问题标题】:Find actual position of an element in WrapPanel在 WrapPanel 中查找元素的实际位置
【发布时间】:2014-05-31 11:00:02
【问题描述】:

我有一个 WrapPanel 和三个按钮。 WrapPanel 中的第三个按钮位于第二行。 我想找到button4的真实位置。

<WrapPanel Height="100" Width="200">
   <Button Content="Button" Height="23" Name="button2" Width="75" />
   <Button Content="Button" Height="23" Name="button3" Width="75" />
   <Button Content="Button" Height="23" Name="button4" Width="75" />
</WrapPanel>

我使用此代码,但它为 0,因为边距为 0。

int top = button4.Margin.Top //I want in this case top become 23 but it is 0.

【问题讨论】:

    标签: c# wpf wrappanel


    【解决方案1】:

    要在WrapPanel 中查找按钮位置,应使用TransformToAncestor (msnd)

     Point currentPoint = button4.TransformToAncestor(myWrapPanel).Transform(new Point(0, 0));
    

    myWrapPanel 是你的WrapPanel

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-26
      • 1970-01-01
      • 1970-01-01
      • 2021-03-19
      • 2013-04-10
      相关资源
      最近更新 更多