0

我想知道如何访问IEnumerable派生自的页面中的所有元素PhoneApplicationPage

如果它是 ASP.Net WebForms,它将如下所示:

    foreach (Control control in this.Controls)
    {
        //Do something
    }

但在 Windows Phone 7.5 中找不到等价物!

4

1 回答 1

1

您可能可以使用VisualTreeHelper类来实现这一点

执行以下操作:

LoopThroughControls(LayoutRoot);

private void LoopThroughControls(UIElement parent)
{
  int count = VisualTreeHelper.GetChildrenCount(parent);
  if (count > 0)
  {
    for (int i = 0; i < count; i++)
    {
      UIElement child = (UIElement)VisualTreeHelper.GetChild(parent, i);
      string childTypeName = child.GetType().ToString();
      LoopThroughControls(child);
    }
  }
} 
于 2012-05-26T12:08:51.437 回答