NavigationService.Navigate 方法

定义

异步导航到指定的源内容。Navigate asynchronously to the specified source content.

重载

Navigate(Uri, Object, Boolean)

异步导航到位于某个 URI 中的源内容,传递一个对象(其中包含在导航过程中进行处理的导航状态),并沙盒处理内容。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)

异步导航到位于某个 URI 中的源内容,并传递一个对象,其中包含要在导航过程中进行处理的数据。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)

异步导航到由 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)

异步导航到位于某个 URI 中的源内容,传递一个对象(其中包含在导航过程中进行处理的导航状态),并沙盒处理内容。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

参数

source
Uri

使用所需内容的 URI 初始化的 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

将内容下载到部分信任的安全沙盒中(如果为 true,则具有默认的 Internet 区域权限集)。Download content into a partial trust security sandbox (with the default Internet zone set of permissions, if true. 默认值为 falseThe default is false.

返回

如果未取消导航,则为 true;否则为 falsetrue if a navigation is not canceled; otherwise, false.

注解

此方法仅适用于独立应用程序和 可扩展应用程序标记语言 (XAML)Extensible Application Markup Language (XAML) 内容。This method is only for standalone applications and 可扩展应用程序标记语言 (XAML)Extensible Application Markup Language (XAML) content.

此方法与 NavigationService.Navigate的行为相同,并通过确保正在下载的内容放入部分信任的安全沙盒(具有默认的 Internet 区域权限集,请参阅WPF 部分信任安全性)来扩展此方法。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).

另请参阅

Navigate(Uri, Object)

异步导航到位于某个 URI 中的源内容,并传递一个对象,其中包含要在导航过程中进行处理的数据。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

参数

source
Uri

使用所需内容的 URI 初始化的 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.

返回

如果未取消导航,则为 true;否则为 falsetrue if a navigation is not canceled; otherwise, false.

示例

下面的示例演示了导航到 URI 和传递导航状态。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

注解

由于导航是异步的,因此可以同时在多个导航中进行。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. 在这种情况下,可能会多次引发 NavigationService 引发的各种导航事件,每个导航事件对应于要导航到的每个内容片段,而不必按顺序请求导航。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. 相反,你可以使用 navigationState 来传递数据,以进行特定于一个导航请求的导航处理。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:

另请参阅

Navigate(Uri)

异步导航到由 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

参数

source
Uri

使用所需内容的 URI 初始化的 Uri 对象。A Uri object initialized with the URI for the desired content.

返回

如果未取消导航,则为 true;否则为 falsetrue if a navigation is not canceled; otherwise, false.

示例

下面的示例演示如何导航到 URI。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

注解

source 的值可以是 Web URLURL 或有效的 pack URI (请参阅WPF 中的 Pack uri)。The value of source can be a Web URLURL or a valid pack URI (see Pack URIs in WPF).

如果满足以下条件,Navigate 将导航到 source 指定的 URI:Navigate will navigate to the URI specified by source if the following conditions are true:

如果 null``source,则会清除现有内容(Content)。If source is null, the existing content (Content) is cleared.

备注

下载 Web 内容时,可能会收到 Web 异常(例如,404:找不到文件)。When downloading Web content, you may receive a Web exception (for example, 404: File Not Found). 可以从 NavigationFailed处理此类异常。You can handle such exceptions from NavigationFailed.

您可以使用 Navigate 导航到内容片段。You can use Navigate to navigate to a content fragment. 如果由 URI 标识的内容是当前内容,则不会再次下载。If the content identified by the URI is the current content, it is not downloaded again.

另请参阅

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

参数

root
Object

一个包含目标导航内容的对象。An object that contains the content to navigate to.

返回

如果未取消导航,则为 true;否则为 falsetrue if a navigation is not canceled; otherwise, false.

示例

下面的示例演示如何导航到包含源内容树的 Page 对象。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

注解

如果满足以下条件,Navigate 将导航到 root 指定的 ObjectNavigate will navigate to the Object specified by root if the following conditions are true:

如果 null``root,则会清除现有内容(Content)。If root is null, the existing content (Content) is cleared.

备注

下载 Web 内容时,可能会收到 Web 异常(例如,404:找不到文件)。When downloading Web content, you may receive a Web exception (for example, 404: File Not Found). 可以从 NavigationFailed处理此类异常。You can handle such exceptions from NavigationFailed.

另请参阅

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

参数

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.

返回

如果未取消导航,则为 true;否则为 falsetrue if a navigation is not canceled; otherwise, false.

示例

下面的示例演示如何导航到包含源内容并传递导航状态的 Page 对象。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

注解

尽管传递对象而不是 URI,此方法与 NavigationService.Navigate具有相同的行为。This method has the same behavior as NavigationService.Navigate, although an object is passed instead of a URI.

另请参阅

适用于