Putting a string in the find box of a DocumentViewer RRS feed

  • Question

  • I have a project with a DocumentViewer, and I'd like to programmatically put a string into the find text box that comes with the DocumentViewer. Does anyone have code that shows how to do this? Thanks.
    Thursday, August 12, 2010 7:10 PM


  • Hi RobertG2009,

    You could use the VisualTreeHelper to find the find TextBox in the DocumentViewer and fill the Text property:


      FindVisualChildByName(Of TextBox)(sender, "FindTextBox").Text = "......"
     Private Function FindVisualChildByName(Of T As DependencyObject)(ByVal parent As DependencyObject, ByVal name As String) As T
      For i As Integer = 0 To VisualTreeHelper.GetChildrenCount(parent) - 1
       Dim child = VisualTreeHelper.GetChild(parent, i)
       Dim controlName As String = TryCast(child.GetValue(Control.NameProperty), String)
       If controlName = name Then
        Return TryCast(child, T)
        Dim result As T = FindVisualChildByName(Of T)(child, name)
        If result IsNot Nothing Then
         Return result
        End If
       End If
      Return Nothing
     End Function


    Bob Bao

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Monday, August 16, 2010 10:50 AM