我有一个包含许多子项的大网格作为按钮,标签和网格。层次结构的最后一个网格包含文本框。
我想循环浏览那些文本框,但这不起作用:
For Each g1 As Grid In LayoutRoot.Children
If (Row.Children.GetType Is GetType(Grid)) Then
For Each g2 As Grid In g1.Children
For Each g3 As Grid In g2.Children
For Each txtbox As TextBox In g3.Children
'Some Code
Next
Next
Next
End If
Next
答案 0 :(得分:1)
你应该只让TextBox
个孩子进行循环:
g3.Children.OfType(Of TextBox)()
完整代码:
For Each g1 In LayoutRoot.Children.OfType(Of Grid)() //change
'If (TypeOf(g1.children) Is grid Then
For Each g2 As Grid In g1.Children
For Each g3 As Grid In g2.Children
For Each txtbox As TextBox In g3.Children.OfType(Of TextBox)() //change
'Some Code
Next
Next
Next
'End If
Next