我想知道如何访问IEnumerable
派生自的页面中的所有元素PhoneApplicationPage
?
如果它是 ASP.Net WebForms,它将如下所示:
foreach (Control control in this.Controls)
{
//Do something
}
但在 Windows Phone 7.5 中找不到等价物!
我想知道如何访问IEnumerable
派生自的页面中的所有元素PhoneApplicationPage
?
如果它是 ASP.Net WebForms,它将如下所示:
foreach (Control control in this.Controls)
{
//Do something
}
但在 Windows Phone 7.5 中找不到等价物!
您可能可以使用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);
}
}
}