Private Function FindVisualChild(Of childItem As DependencyObject)(ByVal obj As DependencyObject) As childItem
For i As Integer = 0 To VisualTreeHelper.GetChildrenCount(obj) - 1
Dim child As DependencyObject = VisualTreeHelper.GetChild(obj, i)
If child IsNot Nothing AndAlso TypeOf child Is childItem Then
Return CType(child, childItem)
Else
Dim childOfChild As childItem = FindVisualChild(Of childItem)(child)
If childOfChild IsNot Nothing Then
Return childOfChild
End If
End If
Next i
Return Nothing
End Function
Private Shared Function GetFrameworkElementByName(Of T As FrameworkElement)(referenceElement As FrameworkElement) As T
Dim child As FrameworkElement = Nothing
For i As Int32 = 0 To VisualTreeHelper.GetChildrenCount(referenceElement) - 1
child = TryCast(VisualTreeHelper.GetChild(referenceElement, i), FrameworkElement)
System.Diagnostics.Debug.WriteLine(child)
If child IsNot Nothing AndAlso child.[GetType]() = GetType(T) Then
Exit For
ElseIf child IsNot Nothing Then
child = GetFrameworkElementByName(Of T)(child)
If child IsNot Nothing AndAlso child.[GetType]() = GetType(T) Then
Exit For
End If
End If
Next
Return TryCast(child, T)
End Function
End Class
Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.
”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.
Our community of experts have been thoroughly vetted for their expertise and industry experience.