1e49806662
-aagiunto assemblato
57 lines
2.2 KiB
VB.net
57 lines
2.2 KiB
VB.net
Module TreeHelperManager
|
|
|
|
Public Function FindVisualParent(Of T As DependencyObject)(ByVal child As DependencyObject) As T
|
|
Dim parentObject As DependencyObject = VisualTreeHelper.GetParent(child)
|
|
If parentObject Is Nothing Then Return Nothing
|
|
Dim parent As T = TryCast(parentObject, T)
|
|
|
|
If parent IsNot Nothing Then
|
|
Return parent
|
|
Else
|
|
Return FindVisualParent(Of T)(parentObject)
|
|
End If
|
|
End Function
|
|
|
|
Public Function FindVisualTwoParent(Of T As DependencyObject, U As DependencyObject)(ByVal child As DependencyObject) As Object
|
|
Dim parentObject As DependencyObject = VisualTreeHelper.GetParent(child)
|
|
If parentObject Is Nothing Then Return Nothing
|
|
If TypeOf parentObject Is T Then
|
|
Return parentObject
|
|
ElseIf TypeOf parentObject Is U Then
|
|
Return parentObject
|
|
Else
|
|
Return FindVisualTwoParent(Of T, U)(parentObject)
|
|
End If
|
|
End Function
|
|
|
|
Public Function FindVisualParents(Of T As DependencyObject, U As DependencyObject, V As DependencyObject)(ByVal child As DependencyObject) As Object
|
|
Dim parentObject As DependencyObject = VisualTreeHelper.GetParent(child)
|
|
If parentObject Is Nothing Then Return Nothing
|
|
If TypeOf parentObject Is T Then
|
|
Return parentObject
|
|
ElseIf TypeOf parentObject Is U Then
|
|
Return parentObject
|
|
ElseIf TypeOf parentObject Is V Then
|
|
Return parentObject
|
|
Else
|
|
Return FindVisualParents(Of T, U, V)(parentObject)
|
|
End If
|
|
End Function
|
|
|
|
' Funzione per trovare un controllo figlio nel Visual Tree
|
|
Public Function FindVisualChild(Of T As DependencyObject)(parent As DependencyObject) As T
|
|
Dim childCount As Integer = VisualTreeHelper.GetChildrenCount(parent)
|
|
For i As Integer = 0 To childCount - 1
|
|
Dim child As DependencyObject = VisualTreeHelper.GetChild(parent, i)
|
|
If TypeOf child Is T Then
|
|
Return DirectCast(child, T)
|
|
Else
|
|
Dim foundChild As T = FindVisualChild(Of T)(child)
|
|
If foundChild IsNot Nothing Then Return foundChild
|
|
End If
|
|
Next
|
|
Return Nothing
|
|
End Function
|
|
|
|
End Module
|