如何在Power Apps中实现屏幕间导航及分类详情联动展示?
Hey there! Let's tackle your questions step by step—starting with basic screen navigation, then diving into your specific category filtering scenario.
1. How to Navigate Between Screens in Power Apps
The core tool for screen navigation is the Navigate() function, and it’s super straightforward to set up:
- Add an interactive control (like a button, or a label with
OnSelectenabled) to your first screen. - Set the control’s
OnSelectproperty toNavigate(YourTargetScreenName), replacingYourTargetScreenNamewith the actual name of your second screen (e.g.,Navigate(Screen2)). - To let users return to the first screen, add a button on the second screen and set its
OnSelectproperty toBack().
For extra polish, you can add transition effects with a second parameter—like Navigate(Screen2, ScreenTransition.Fade) for a smooth fade-in animation.
2. Filtering Second Screen Results by Selected Category
For your scenario where clicking a category on the first screen shows only that category’s details on the second, here are two reliable approaches:
Option 1: Using a Global Variable (Simple for Small Apps)
- On your first screen, select the Carpet button and set its
OnSelectproperty to:Set(varSelectedCategory, "Carpet"); Navigate(Screen2) - Repeat this for the other buttons, updating the category value:
- Hardwood button:
Set(varSelectedCategory, "Hardwood"); Navigate(Screen2) - Tile button:
Set(varSelectedCategory, "Tile"); Navigate(Screen2)
- Hardwood button:
- On the second screen, use the
Filter()function to narrow your data source to the selected category. If you’re using a Gallery to display subcategories, set itsItemsproperty to:
ReplaceFilter(YourDataSource, Category = varSelectedCategory)YourDataSourcewith the name of your actual data source (e.g., a SharePoint list, Dataverse table, or collection holding category details).
Option 2: Using Context Variables (Cleaner for Isolated Data)
If you want to avoid global variables (to prevent unintended side effects in larger apps), pass the category directly via the Navigate() function’s context parameter:
- For the Carpet button’s
OnSelect:Navigate(Screen2, None, {ctxSelectedCategory: "Carpet"}) - Update the other buttons similarly (e.g.,
{ctxSelectedCategory: "Hardwood"}for the Hardwood button). - On the second screen, reference the context variable in your Gallery’s
Itemsproperty:Filter(YourDataSource, Category = ctxSelectedCategory)
Either method will ensure that when a user clicks a category on the first screen, the second screen only loads the matching subcategory data.
内容的提问来源于stack exchange,提问作者Mufaddal

