导航拓扑概述Navigation Topologies Overview

本概述介绍了 WPF 中的导航拓扑。This overview provides an introduction to navigation topologies in WPF. 三个常见导航拓扑及示例将在随后讨论。Three common navigation topologies, with samples, are subsequently discussed.

备注

在阅读本主题之前,您应该熟悉使用页面函数在 WPF 中进行结构化导航的概念。Before reading this topic, you should be familiar with the concept of structured navigation in WPF using page functions. 有关这两个主题的详细信息,请参阅结构化导航概述For more information on both of these topics, see Structured Navigation Overview.

本主题包含以下各节:This topic contains the following sections:

在 WPF 中,导航通常由Page具有超链接 (Hyperlink) 的页面组成,这些页面在单击时导航到其他页面。In WPF, navigation typically consists of pages (Page) with hyperlinks (Hyperlink) that navigate to other pages when clicked. 导航到的页面由统一的资源标识符 (URI) 标识(请参阅WPF 中的 Pack URI)。Pages that are navigated to are identified by uniform resource identifiers (URIs) (see Pack URIs in WPF). 请考虑以下显示页面、超链接和统一资源标识符 (URI) 的简单示例:Consider the following simple example that shows pages, hyperlinks, and uniform resource identifiers (URIs):

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" WindowTitle="Page1">
  <Hyperlink NavigateUri="Page2.xaml">Navigate to Page2</Hyperlink>
</Page>
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" WindowTitle="Page2">
  <Hyperlink NavigateUri="Page1.xaml">Navigate to Page1</Hyperlink>
</Page>

这些页面排列在导航拓扑中,其结构取决于如何在页面之间导航。These pages are arranged in a navigation topology whose structure is determined by how you can navigate between the pages. 此特定导航拓扑适用于简单的应用场景,尽管导航可以要求更复杂的拓扑(其中的一些只能在应用程序运行时定义)。This particular navigation topology is suitable in simple scenarios, although navigation can require more complex topologies, some of which can only be defined when an application is running.

本主题涵盖三种常见的导航拓扑:固定线性固定分层动态生成This topic covers three common navigation topologies: fixed linear, fixed hierarchical, and dynamically generated. 每个导航拓扑都使用示例进行演示,该示例具有UIUI下图所示的示例:Each navigation topology is demonstrated with a sample that has a UIUI like the one that is shown in the following figure:

包含数据项和导航按钮的任务页。

结构化导航拓扑Structured Navigation Topologies

有两种广义类型的导航拓扑:There are two broad types of navigation topologies:

  • 固定拓扑:在编译时定义,在运行时不能更改。Fixed Topology: defined at compile time and does not change at run time. 按线性或层次顺序在固定序列的页面之间导航时,固定拓扑将很有用。Fixed topologies are useful for navigation through a fixed sequence of pages in either a linear or hierarchical order.

  • 动态拓扑:在运行时基于从用户、应用程序或系统收集的输入进行定义。Dynamic Topology: defined at run time based on input that is collected from the user, the application, or the system. 当页面可以按不同序列进行导航时,动态拓扑将很有用。Dynamic topologies are useful when pages can be navigated in different sequences.

虽然使用页可以创建导航拓扑,但是这些示例使用页函数,因为它们提供附加支持,从而通过拓扑页简化对传递和返回数据的支持。Although it is possible to create navigation topologies using pages, the samples use page functions because they provide additional support that simplifies support for passing and returning data through the pages of a topology.

固定线性拓扑类似于向导的结构,即在固定序列中导航一个或多个向导页。A fixed linear topology is analogous to the structure of a wizard that has one or more wizard pages that are navigated in a fixed sequence. 下图显示了具有固定线性拓扑的向导的高级结构和流程:The following figure shows the high-level structure and flow of a wizard with a fixed linear topology:

显示固定线性拓扑的图表。

在固定线性拓扑中导航的典型行为包括以下内容:The typical behaviors for navigating over a fixed linear topology include the following:

  • 从调用页导航到启动程序页,启动程序页初始化向导并导航到第一个向导页。Navigating from the calling page to a launcher page that initializes the wizard and navigates to the first wizard page. 启动器页 (UIUIPageFunction<T>-) 不是必需的,因为调用页可以直接调用第一个向导页。A launcher page (a UIUI-less PageFunction<T>) is not required, since a calling page can call the first wizard page directly. 但是,使用启动程序页可以简化向导初始化,特别是初始化较复杂时。Using a launcher page, however, can simplify wizard initialization, particularly if initialization is complex.

  • 用户可以使用“后退”和“前进”按钮(或超链接)在不同的页面之间导航。Users can navigate between pages by using Back and Forward buttons (or hyperlinks).

  • 用户可以使用日志在不同的页面之间导航。Users can navigate between pages using the journal.

  • 用户可以通过按下“取消”按钮从任何向导页取消向导。Users can cancel the wizard from any wizard page by pressing a Cancel button.

  • 用户可以在最后一个向导页上通过按下“完成”按钮来接受向导。Users can accept the wizard on the last wizard page by pressing a Finish button.

  • 如果向导已取消,该向导会返回相应结果,但不返回任何数据。If a wizard is canceled, the wizard returns an appropriate result, and does not return any data.

  • 如果用户接受向导,该向导会返回相应结果并返回所收集的数据。If a user accepts a wizard, the wizard returns an appropriate result, and returns the data it collected.

  • 向导完成(接受或取消)后,向导所包含的页便会从日志中删除。When the wizard is complete (accepted or canceled), the pages that the wizard comprises are removed from the journal. 这使得每个向导实例都保持独立,从而避免潜在的数据反常或状态异常。This keeps each instance of the wizard isolated, thereby avoiding potential data or state anomalies.

在固定分层拓扑中动态导航Dynamic Navigation over a Fixed Hierarchical Topology

在某些应用程序中,页面允许导航到两个或多个其他页面,如下图所示:In some applications, pages allow navigation to two or more other pages, as shown in the following figure:

显示可导航到多个页面的页面的图表。

此结构称为固定分层拓扑,分层的遍历序列通常在运行时由应用程序或用户确定。This structure is known as a fixed hierarchical topology, and the sequence in which the hierarchy is traversed is often determined at run time by either the application or the user. 运行时,对于允许导航到两个或更多其他页的分层中的每个页面,会收集确定导航到的页所需的数据。At run time, each page in the hierarchy that allows navigation to two or more other pages gathers the data required to determine which page to navigate to. 下图说明了基于上图的几种可能的导航序列之一:The following figure illustrates one of several possible navigation sequences based on the previous figure:

显示可能的导航序列的图表。

即使固定分层结构中的页导航序列在运行时确定,用户体验仍会与固定线性拓扑的用户体验相同:Even though the sequence in which pages in a fixed hierarchical structure are navigated is determined at run time, the user experience is the same as the user experience for a fixed linear topology:

  • 从调用页导航到启动程序页,启动程序页初始化向导并导航到第一个向导页。Navigating from the calling page to a launcher page that initializes the wizard and navigates to the first wizard page. 启动器页 (UIUIPageFunction<T>-) 不是必需的,因为调用页可以直接调用第一个向导页。A launcher page (a UIUI-less PageFunction<T>) is not required, since a calling page can call the first wizard page directly. 但是,使用启动程序页可以简化向导初始化,特别是初始化较复杂时。Using a launcher page, however, can simplify wizard initialization, particularly if initialization is complex.

  • 用户可以使用“后退”和“前进”按钮(或超链接)在不同的页面之间导航。Users can navigate between pages by using Back and Forward buttons (or hyperlinks).

  • 用户可以使用日志在不同的页面之间导航。Users can navigate between pages using the journal.

  • 如果用户通过日志向后导航,他们可以更改导航序列。Users can change the navigation sequence if they navigate back through the journal.

  • 用户可以通过按下“取消”按钮从任何向导页取消向导。Users can cancel the wizard from any wizard page by pressing a Cancel button.

  • 用户可以在最后一个向导页上通过按下“完成”按钮来接受向导。Users can accept the wizard on the last wizard page by pressing a Finish button.

  • 如果向导已取消,该向导会返回相应结果,但不返回任何数据。If a wizard is canceled, the wizard returns an appropriate result, and does not return any data.

  • 如果用户接受向导,该向导会返回相应结果并返回所收集的数据。If a user accepts a wizard, the wizard returns an appropriate result, and returns the data it collected.

  • 向导完成(接受或取消)后,向导所包含的页便会从日志中删除。When the wizard is complete (accepted or canceled), the pages that the wizard comprises are removed from the journal. 这使得每个向导实例都保持独立,从而避免潜在的数据反常或状态异常。This keeps each instance of the wizard isolated, thereby avoiding potential data or state anomalies.

在某些应用程序中,两个或更多页的导航序列只能在运行时由用户、应用程序或外部数据确定。In some applications, the sequence in which two or more pages are navigated can only be determined at run time, whether by the user, the application, or external data. 下图说明了一组具有不确定导航序列的页面:The following figure illustrates a set of pages with an undetermined navigation sequence:

具有不确定导航序列的一组页面。

下图显示了用户在运行时选择的导航序列:The next figure illustrates a navigation sequence that was chosen by the user at run time:

显示运行时选择的导航序列的图表。

该导航序列称为动态生成的拓扑。The navigation sequence is known as a dynamically generated topology. 对于用户而言,与其他导航拓扑一样,用户体验与以前拓扑的用户体验相同:For the user, as with the other navigation topologies, the user experience is the same as it is for the previous topologies:

  • 从调用页导航到启动程序页,启动程序页初始化向导并导航到第一个向导页。Navigating from the calling page to a launcher page that initializes the wizard and navigates to the first wizard page. 启动器页 (UIUIPageFunction<T>-) 不是必需的,因为调用页可以直接调用第一个向导页。A launcher page (a UIUI-less PageFunction<T>) is not required, since a calling page can call the first wizard page directly. 但是,使用启动程序页可以简化向导初始化,特别是初始化较复杂时。Using a launcher page, however, can simplify wizard initialization, particularly if initialization is complex.

  • 用户可以使用“后退”和“前进”按钮(或超链接)在不同的页面之间导航。Users can navigate between pages by using Back and Forward buttons (or hyperlinks).

  • 用户可以使用日志在不同的页面之间导航。Users can navigate between pages using the journal.

  • 用户可以通过按下“取消”按钮从任何向导页取消向导。Users can cancel the wizard from any wizard page by pressing a Cancel button.

  • 用户可以在最后一个向导页上通过按下“完成”按钮来接受向导。Users can accept the wizard on the last wizard page by pressing a Finish button.

  • 如果向导已取消,该向导会返回相应结果,但不返回任何数据。If a wizard is canceled, the wizard returns an appropriate result, and does not return any data.

  • 如果用户接受向导,该向导会返回相应结果并返回所收集的数据。If a user accepts a wizard, the wizard returns an appropriate result, and returns the data it collected.

  • 向导完成(接受或取消)后,向导所包含的页便会从日志中删除。When the wizard is complete (accepted or canceled), the pages that the wizard comprises are removed from the journal. 这使得每个向导实例都保持独立,从而避免潜在的数据反常或状态异常。This keeps each instance of the wizard isolated, thereby avoiding potential data or state anomalies.

另请参阅See also