title: Closing a form from user control using dependency object
body: <p>I have a navigation control that is displayed in multiple pages. So, I have no way to identify the exact class name during design time. Now, when user navigates to different page, I want to hide the current page. Basically, a typical menubar behaviour. I am able to get the outermost element as a dependency object using the code below.</p>
  
  <pre><code>    Private Function GetTopLevelControl(ByVal control As DependencyObject) As DependencyObject
      Dim tmp As New DependencyObject
      tmp = control
      Dim parent As New DependencyObject
      parent = Nothing
  
      While Not VisualTreeHelper.GetParent(tmp) Is Nothing
          parent = VisualTreeHelper.GetParent(tmp)
      End While
  
      Return parent
  End Function
  </code></pre>
  
  <p>Now, on the mouse down event, I am trying to write code to hide this parent object. </p>
  
  <pre><code>        Private Sub Menu_Nomination_MouseDown(sender As Object, e As MouseButtonEventArgs)
      Dim surveySearchPage As New SurveySearch
      surveySearchPage.Show()
      Dim parentControl As DependencyObject
      parentControl = GetTopLevelControl(Me)
      parentControl
  
  End Sub
  </code></pre>
  
  <p>Problem is parentControl object has no hide or close property at all. So, I am currently stuck in trying to close the page. </p>