Rediger

Del via


NavigationService.Navigate Method

Definition

Navigate asynchronously to the specified source content.

Overloads

Navigate(Uri, Object, Boolean)

Navigate asynchronously to source content located at a URI, pass an object containing navigation state for processing during navigation, and sandbox the content.

Navigate(Uri, Object)

Navigate asynchronously to source content located at a URI, and pass an object that contains data to be used for processing during navigation.

Navigate(Uri)

Navigate asynchronously to content that is specified by a URI.

Navigate(Object)

Navigate asynchronously to content that is contained by an object.

Navigate(Object, Object)

Navigate asynchronously to content that is contained by an object, and pass an object that contains data to be used for processing during navigation.

Navigate(Uri, Object, Boolean)

Navigate asynchronously to source content located at a URI, pass an object containing navigation state for processing during navigation, and sandbox the content.

public:
 bool Navigate(Uri ^ source, System::Object ^ navigationState, bool sandboxExternalContent);
public bool Navigate (Uri source, object navigationState, bool sandboxExternalContent);
member this.Navigate : Uri * obj * bool -> bool
Public Function Navigate (source As Uri, navigationState As Object, sandboxExternalContent As Boolean) As Boolean

Parameters

source
Uri

A Uri object initialized with the URI for the desired content.

navigationState
Object

An object that contains data to be used for processing during navigation.

sandboxExternalContent
Boolean

Download content into a partial trust security sandbox (with the default Internet zone set of permissions, if true. The default is false.

Returns

true if a navigation is not canceled; otherwise, false.

Remarks

This method is only for standalone applications and Extensible Application Markup Language (XAML) content.

This method exhibits the same behavior as NavigationService.Navigate, and extends it by ensuring that the content that is being downloaded is placed into a partial trust security sandbox (with the default Internet zone set of permissions - see WPF Partial Trust Security).

See also

Applies to

Navigate(Uri, Object)

Navigate asynchronously to source content located at a URI, and pass an object that contains data to be used for processing during navigation.

public:
 bool Navigate(Uri ^ source, System::Object ^ navigationState);
public bool Navigate (Uri source, object navigationState);
member this.Navigate : Uri * obj -> bool
Public Function Navigate (source As Uri, navigationState As Object) As Boolean

Parameters

source
Uri

A Uri object initialized with the URI for the desired content.

navigationState
Object

An object that contains data to be used for processing during navigation.

Returns

true if a navigation is not canceled; otherwise, false.

Examples

The following example demonstrates navigating to a URI and passing navigation state.

void goButton_Click(object sender, RoutedEventArgs e)
{
    this.NavigationService.Navigate(new Uri(this.addressTextBox.Text), DateTime.Now);
}
void NavigationService_LoadCompleted(object sender, NavigationEventArgs e)
{
    DateTime requestDateTime = (DateTime)e.ExtraData;
    string msg = string.Format("Request started {0}\nRequest completed {1}", requestDateTime, DateTime.Now);
    MessageBox.Show(msg);
}
Private Sub goButton_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
    Me.NavigationService.Navigate(New Uri(Me.addressTextBox.Text), Date.Now)
End Sub
Private Sub NavigationService_LoadCompleted(ByVal sender As Object, ByVal e As NavigationEventArgs)
    Dim requestDateTime As Date = CDate(e.ExtraData)
    Dim msg As String = String.Format("Request started {0}" & vbLf & "Request completed {1}", requestDateTime, Date.Now)
    MessageBox.Show(msg)
End Sub

Remarks

Since navigations are asynchronous, it is possible for multiple navigations to be in progress at the same time. For example, if there are two child frames on a single page, both frames could be navigating. In this case, the various navigation events that are raised by NavigationService may be raised multiple times, one for each piece of content that is being navigated to, and not necessarily in order that the navigations were requested. Consequently, if a particular navigation request needs to process data that is specific to the individual request, it cannot use data that is available to all navigation requests. Instead, you can use navigationState to pass data for navigation processing that is specific to one navigation request.

The following event arguments provide access to navigation state:

See also

Applies to

Navigate(Uri)

Navigate asynchronously to content that is specified by a URI.

public:
 bool Navigate(Uri ^ source);
public bool Navigate (Uri source);
member this.Navigate : Uri -> bool
Public Function Navigate (source As Uri) As Boolean

Parameters

source
Uri

A Uri object initialized with the URI for the desired content.

Returns

true if a navigation is not canceled; otherwise, false.

Examples

The following example shows how to navigate to a URI.

void goButton_Click(object sender, RoutedEventArgs e)
{
    this.NavigationService.Navigate(new Uri(this.addressTextBox.Text));
}
Private Sub goButton_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
    Me.NavigationService.Navigate(New Uri(Me.addressTextBox.Text))
End Sub

Remarks

The value of source can be a Web URL or a valid pack URI (see Pack URIs in WPF).

Navigate will navigate to the URI specified by source if the following conditions are true:

If source is null, the existing content (Content) is cleared.

Note

When downloading Web content, you may receive a Web exception (for example, 404: File Not Found). You can handle such exceptions from NavigationFailed.

You can use Navigate to navigate to a content fragment. If the content identified by the URI is the current content, it is not downloaded again.

See also

Applies to

Navigate(Object)

Navigate asynchronously to content that is contained by an object.

public:
 bool Navigate(System::Object ^ root);
public bool Navigate (object root);
member this.Navigate : obj -> bool
Public Function Navigate (root As Object) As Boolean

Parameters

root
Object

An object that contains the content to navigate to.

Returns

true if a navigation is not canceled; otherwise, false.

Examples

The following example shows how to navigate to a Page object containing the source content tree.

void goObjectButton_Click(object sender, RoutedEventArgs e)
{
    this.NavigationService.Navigate(new ContentPage());
}
Private Sub goObjectButton_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
    Me.NavigationService.Navigate(New ContentPage())
End Sub

Remarks

Navigate will navigate to the Object specified by root if the following conditions are true:

If root is null, the existing content (Content) is cleared.

Note

When downloading Web content, you may receive a Web exception (for example, 404: File Not Found). You can handle such exceptions from NavigationFailed.

See also

Applies to

Navigate(Object, Object)

Navigate asynchronously to content that is contained by an object, and pass an object that contains data to be used for processing during navigation.

public:
 bool Navigate(System::Object ^ root, System::Object ^ navigationState);
public bool Navigate (object root, object navigationState);
member this.Navigate : obj * obj -> bool
Public Function Navigate (root As Object, navigationState As Object) As Boolean

Parameters

root
Object

An object that contains the content to navigate to.

navigationState
Object

An object that contains data to be used for processing during navigation.

Returns

true if a navigation is not canceled; otherwise, false.

Examples

The following example shows how to navigate to a Page object containing the source content, and passing navigation state.

void goButton_Click(object sender, RoutedEventArgs e)
{
    this.NavigationService.Navigate(new ContentPage(), DateTime.Now);
}
void NavigationService_LoadCompleted(object sender, NavigationEventArgs e)
{
    DateTime requestDateTime = (DateTime)e.ExtraData;
    string msg = string.Format("Request started {0}\nRequest completed {1}", requestDateTime, DateTime.Now);
    MessageBox.Show(msg);
}
Private Sub goButton_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
    Me.NavigationService.Navigate(New ContentPage(), Date.Now)
End Sub
Private Sub NavigationService_LoadCompleted(ByVal sender As Object, ByVal e As NavigationEventArgs)
    Dim requestDateTime As Date = CDate(e.ExtraData)
    Dim msg As String = String.Format("Request started {0}" & vbLf & "Request completed {1}", requestDateTime, Date.Now)
    MessageBox.Show(msg)
End Sub

Remarks

This method has the same behavior as NavigationService.Navigate, although an object is passed instead of a URI.

See also

Applies to