PowerApps 中的 Back 與 Navigate 函式Back and Navigate functions in PowerApps

變更顯示的畫面。Changes which screen is displayed.

概觀Overview

大部分的應用程式包含多個畫面。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. 在該公式中,您可以指定視覺轉換,例如淡化,以控制一個畫面變更為另一個畫面的方法。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.

說明Description

BackBack

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 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.

語法Syntax

Back()Back()

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.

範例Examples

公式Formula 說明Description 結果Result
Navigate( Details, ScreenTransition.None )Navigate( Details, ScreenTransition.None ) 顯示詳細資料畫面而在內容變數的值中沒有轉換或變更。Displays the Details screen with no transition or change in value for a context variable. 隨即快速出現詳細資料畫面。The Details screen appears quickly.
Navigate( Details, ScreenTransition.Fade )Navigate( Details, ScreenTransition.Fade ) 顯示詳細資料畫面與淡化轉換。Displays the Details screen with a Fade transition. 內容變數的任何值都不會變更。No value of a context variable is changed. 目前畫面會淡化以顯示詳細資料畫面。The current screen fades away to show the Details screen.
Navigate( Details, ScreenTransition.Fade, { ID: 12 } )Navigate( Details, ScreenTransition.Fade, { ID: 12 } ) 顯示詳細資料畫面與淡化轉換,並將識別碼內容變數的值變更為 12Displays the Details screen with a Fade transition, and updates the value of the ID context variable to 12. 目前畫面會淡化以顯示詳細資料畫面,且該畫面上的內容變數識別碼會設定為 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 } ) 顯示詳細資料畫面與淡化轉換。Displays the Details screen with a Fade transition. 識別碼內容變數的值更新為 12,並將陰影內容變數的值更新為 Color.RedUpdates the value of the ID context variable to 12, and updates the value of the Shade context variable to Color.Red. 目前畫面會淡化以顯示詳細資料畫面。The current screen fades away to show the Details screen. 詳細資料畫面上的內容變數識別碼會設為 12,內容變數陰影設為 Color.RedThe context variable ID on the Details screen is set to 12, and the context variable Shade is set to Color.Red. 如果您將詳細資料畫面上控制項的 Fill 屬性設為陰影,該控制項會顯示為紅色。If you set the Fill property of a control on the Details screen to Shade, that control would display as red.

循序漸進Step-by-step

  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