我有一个显示在多个页面中的导航控件。所以,我无法在设计时确定确切的类名。现在,当用户导航到不同的页面时,我想隐藏当前页面。基本上,典型的菜单栏行为。我可以使用下面的代码将最外层的元素作为依赖对象。
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
现在,在鼠标按下事件中,我正在尝试编写代码来隐藏此父对象。
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
问题是parentControl对象根本没有隐藏或关闭属性。所以,我目前只是试图关闭页面。