WPF navigation via buttons
button, navigation, wpf
Solution
I feel like a goof ball for answering my own question, but i figured it out at long last!
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click
Dim pg As Page = CType(GetDependencyObjectFromVisualTree(Me, GetType(Page)), Page)
Dim newPage As %desired uri here% = New %desired uri here%
pg.NavigationService.Navigate(newPage)
End Sub
Private Function GetDependencyObjectFromVisualTree(ByVal startObject As DependencyObject, ByVal type As Type) As DependencyObject
'Walk the visual tree to get the parent(ItemsControl)
'of this control
Dim parent As DependencyObject = startObject
While (Not (parent) Is Nothing)
If type.IsInstanceOfType(parent) Then
Exit While
Else
parent = VisualTreeHelper.GetParent(parent)
End If
End While
Return parent
End Function
This function i found here (http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/f8b02888-7e1f-42f4-83e5-448f2af3d207) will allow for the use of NavigationService inside of a user control.
~N
Problem
Question: Is there a way to make a button behave like a hyperlink inside of a user control? I've been searching around for a few days now and haven't found anyone who has addressed this. How do you use a button to navigate in a WPF application? Specifically how do you make a button inside of a user control navigate it's host frame? Bare in mind that User controls do not have direct access to the host frame. so simply: ``` this.NavigationService.Navigate(new Uri(this.addressTextBox.Text)); ``` won't work. I'm using user controls. If you are using only pages, this is the answer you are looking for, if you are using UserControls, look at my answer below.