This is the function I've got lurking in my library. I've never had any trouble with it, but it does have a GetChildrenCount() call in it so if that's not working for you you may have a bigger problem.
Public Shared Function FindVisualChild(Of T As DependencyObject)(ByVal element As DependencyObject) As T
If element Is Nothing Then
Return Nothing
ElseIf TypeOf (element) Is T Then
Return element
Else
Dim count = VisualTreeHelper.GetChildrenCount(element)
For index As Integer = 0 To count - 1
Dim child As DependencyObject = VisualTreeHelper.GetChild(element, index)
If TypeOf (child) Is T Then
Return child
Else
Dim grandchild As T = FindVisualChild(Of T)(child)
If grandchild IsNot Nothing Then Return grandchild
End If
Next
End If
Return Nothing
End Function
Usage: x = FindVisualChild(Of DockPanel)(ParentObject)
Yes, I know it's VB. It's about time one of you C# guys had to convert code for once! :)