Microsoft PowerApps 中的 Back 和 Navigate 函数Back and Navigate functions in PowerApps

更改显示的屏幕。Changes which screen is displayed.


大多数应用都包含多个屏幕。Most apps contain multiple screens. BackNavigate 函数可用于更改所显示的屏幕。Use the Back and Navigate function to change which screen is displayed. 例如,如果你希望用户在选中某个按钮后显示其他屏幕,请将该按钮的 OnSelect 属性设置为一个包含 Navigate 函数的公式。For example, set the OnSelect property of a button to a formula that includes a Navigate function if you want to show a different screen when a user selects that button. 在这个公式中,你可以指定视觉变换效果(比如 Fade)来控制屏幕切换方式。In that formula, you can specify a visual transition, such as Fade, to control how one screen changes to another.

BackNavigate 只能更改当前显示的屏幕。Back and Navigate change only which screen is displayed. 当前未显示的屏幕仍然在后台运行。Screens that aren't currently displayed continue to operate behind the scenes. 你可以构建公式来引用另一个屏幕上控件的属性。You can build formulas that refer to properties of controls on another screen. 例如,用户可以更改某一个屏幕上滑块的值,导航到在公式中使用这个值的另一个屏幕,看看对新屏幕的显示有何影响。For example, a user can change the value of a slider on one screen, navigate to a different screen that uses that value in a formula, and see how it affects what happens in the new screen. 然后,用户可以导航回原来的屏幕,并且会发现滑块保留了自己的值。The user can then navigate back to the original screen and see that the slider has retained its value.

当用户在屏幕之间导航时,上下文变量也会保留。Context variables are also preserved when a user navigates between screens. 你可以使用 Navigate 设置公式会显示的屏幕的一个或多个上下文变量,这是从屏幕外部设置上下文变量的唯一方法。You can use Navigate to set one or more context variables for the screen that the formula will display, which is the only way to set a context variable from outside the screen. 这个方法可用于将参数传递到屏幕。You can use this approach to pass parameters to a screen. 如果你使用过另一款编程工具,就会发现这个方法与将参数传递给过程非常相似。If you've used another programming tool, this approach is similar to passing parameters to procedures.



Back 函数用于显示最近显示的屏幕。The Back function displays the screen that was most recently displayed. 无需为这个函数指定任何参数。You don't specify any arguments for this function.

在第一个参数中,指定要显示的屏幕的名称。In the first argument, specify the name of the screen to display.

在第二个参数中,指定旧屏幕切换为新屏幕的方式:In the second argument, specify how the old screen changes to the new screen:

Transition 参数Transition Argument 说明Description
ScreenTransition.CoverScreenTransition.Cover 新屏幕将滑入视图,盖住当前屏幕。The new screen slides into view, covering the current screen.
ScreenTransition.FadeScreenTransition.Fade 旧屏幕淡出以显示新屏幕。The old screen fades away to reveal the new screen.
ScreenTransition.NoneScreenTransition.None 新屏幕快速替换旧屏幕。The old screen is quickly replaced with the new screen.
ScreenTransition.UnCoverScreenTransition.UnCover 旧屏幕滑出视图,以显示新屏幕。The old screen slides out of view, uncovering the new screen.

可以使用 Navigate 创建或更新的新屏幕的上下文变量。You can use Navigate to create or update context variables of the new screen. 第三个参数是可选的,它可用于传递一条记录,其中包含上下文变量名称(以名称的形式)和上下文变量的新值。As an optional third argument, pass a record that contains the context-variable name as a column name and the new value for the context variable. 这条记录就是用于 UpdateContext 函数的记录。This record is the same as the record that you use with the UpdateContext function.

设置旧屏幕的 OnHidden 属性和/或新屏幕的 OnVisible 属性,以在过渡期间进行其他更改。Set the OnHidden property of the old screen, the OnVisible property of the new screen, or both to make additional changes during the transition. App.ActiveScreen 属性将更新以反映更改。The App.ActiveScreen property will be updated to reflect the change.

Back 通常返回 true,但如果当前显示的是第一个屏幕(之前没有显示其他屏幕),则会返回 falseBack normally returns true but returns false if the user is on the first screen shown and there is no previous screen. Navigate 通常返回 true,但如果它的某个参数有问题,则会返回 falseNavigate normally returns true but returns false if there is a problem with one of its arguments.

这两个函数只能在行为公式中使用。You can use these functions only within a behavior formula.



Navigate( Screen, Transition [, UpdateContextRecord ] )Navigate( Screen, Transition [, UpdateContextRecord ] )

  • Screen - 必需。Screen - Required. 要显示的屏幕。The screen to display.
  • Transition - 必需。Transition - Required. 切换屏幕时要使用的视觉过渡效果。The visual transition to use between the current screen and the next screen. 请参阅本主题前文中所述此参数的有效值列表。See the list of valid values for this argument earlier in this topic.
  • UpdateContextRecord - 可选。UpdateContextRecord - Optional. 一条记录,其中包含至少一列的名称以及每列的值。A record that contains the name of at least one column and a value for each column. 这一条记录用于更新新屏幕的上下文变量,就像传递到 UpdateContext 函数一样。This record updates the context variables of the new screen as if passed to the UpdateContext function.


公式Formula 说明Description 结果Result
Navigate( Details, ScreenTransition.None )Navigate( Details, ScreenTransition.None ) 显示 Details 屏幕,没有任何过渡效果,也不会更改上下文变量的值。Displays the Details screen with no transition or change in value for a context variable. Details 屏幕会快速显示。The Details screen appears quickly.
Navigate( Details, ScreenTransition.Fade )Navigate( Details, ScreenTransition.Fade ) 淡入淡出过渡效果显示 Details 屏幕。Displays the Details screen with a Fade transition. 不更改上下文变量的任何值。No value of a context variable is changed. 当前屏幕淡化消失,以显示 Details 屏幕。The current screen fades away to show the Details screen.
Navigate( Details, ScreenTransition.Fade, { ID: 12 } )Navigate( Details, ScreenTransition.Fade, { ID: 12 } ) 使用淡入淡出过渡效果显示 Details 屏幕,并且将 ID 上下文变量的值更新为 12Displays the Details screen with a Fade transition, and updates the value of the ID context variable to 12. 当前屏幕淡化消失,以显示 Details 屏幕,并且将这个屏幕的上下文变量 ID 设置为 12The current screen fades away to show the Details screen, and the context variable ID on that screen is set to 12.
Navigate( Details, ScreenTransition.Fade, { ID: 12 , Shade: Color.Red } )Navigate( Details, ScreenTransition.Fade, { ID: 12 , Shade: Color.Red } ) 淡入淡出过渡效果显示 Details 屏幕。Displays the Details screen with a Fade transition. ID 上下文变量的值更新为 12,并且将 Shade 上下文变量的值更新为 Color.RedUpdates the value of the ID context variable to 12, and updates the value of the Shade context variable to Color.Red. 当前屏幕淡化消失,以显示 Details 屏幕。The current screen fades away to show the Details screen. Details 屏幕的上下文变量 ID 设置为 12,并且将上下文变量 Shade 设置为 Color.RedThe context variable ID on the Details screen is set to 12, and the context variable Shade is set to Color.Red. 如果将 Details 屏幕上某一控件的 Fill 属性设置为 Shade,则该控件会显示为红色。If you set the Fill property of a control on the Details screen to Shade, that control would display as red.


  1. 将默认屏幕命名为 DefaultScreen,在其中添加一个标签,并设置这个标签的 Text 属性,使其显示 DefaultName the default screen DefaultScreen, add a label to it, and set the Text property of that label so that it shows Default.
  2. 添加一个屏幕并将其命名为 AddlScreenAdd a screen, and name it AddlScreen.
  3. AddlScreen 添加一个标签,并设置标签的 Text 属性,使其显示 AddlAdd a label to AddlScreen, and set the Text property of the label so that it shows Addl.
  4. AddlScreen 上添加一个按钮,将其 OnSelect 属性设置为以下函数:Add a button to AddlScreen, and set its OnSelect property to this function:
    Navigate(DefaultScreen, ScreenTransition.Fade)Navigate(DefaultScreen, ScreenTransition.Fade)
  5. AddlScreen 中,按 F5,然后选中这个按钮。From the AddlScreen, press F5, and then select the button.
    随即会显示 DefaultScreenDefaultScreen appears.

再举一例Another example