Replies: 1 comment
-
Hi @zshall thanks for all of the details! Multiple things here that I will try and cover. First, yes it should absolutely be possible to define a Model and XAML for the content of your Flyout so it can be re-used. The Navigation extensions are smart enough to determine how a specific page should be displayed in the app based on the type of view that you are navigating to. Detailed a bit here. So, what you could do is create a Flyout called NavFlyout and a corresponding Model (called NavFlyoutModel) like you did above. After that, you would need to define a route for that flyout in order to navigate to it. So you would need something like: Now you can navigate to open the flyout via the "Nav" route like so: <Button uen:Navigation.Request="Nav" /> Or in code like: await _navigator.NavigateViewModelAsync<NavFlyoutModel>(this);
// or...
await _navigator.NaviagateRouteAsync(this, "Nav"); Notice above that I am not using the "!", or the Now, as for navigating from the flyout. I am assuming you want to be able to click on a button in the Flyout and have it close the Flyout and navigate from the main page of the application? For that, you will need to fiddle with your route definitions a bit. Since the route for the NavFlyout can be seen as being "outside" of the main nav route logic for your MainPage/SyncPage/SettingsOverviewPage, we need to make sure it isn't defined at the same level as those routes. As an easier way of explaining, I have created a small sample app that I think replicates what you are trying to do. You can find it hosted on my GitHub here: https://github.com/kazo0/NavFlyoutApp Take a look at the routes that I have defined: You'll see that the Nav route is outside of the Main flow, since it's more of a globally accessible route that can display the Flyout over the rest of the app. Now, anytime you attempt to navigate to a route from within the Flyout, and that route exists at another level, it will close the Flyout and perform the navigation from the context that originally opened the Flyout. Now we can navigate from within the Flyout and get it to change on the main page: And you'll notice that the TextBlock I have in the Flyout is properly populated with the text from the NavModel Recording.2024-07-25.164439.mp4 |
Beta Was this translation helpful? Give feedback.
-
Hi all,
I'm new to Uno and mobile app development and am trying to implement some basic navigation in an Uno project and have been having some trouble getting started. I've read the following links:
My project is using XAML, MVUX, and targets Android primarily. I defined some routes in
App.xaml.cs
:In MainPage.xaml I added a navigation bar that would open the navigation drawer:
The flyout page looks like this:
After adding a few pages I realized that I've needed to include the
<utu:NavigationBar>
on every page and reimplement theNavigateToXAsync()
code on every page as well as resolve localized strings for the menu buttons on each page as well; It seems like I'm doing something fundamentally wrong, as if I'm not careful when I change pages the navigation button text might disappear or the click handlers will stop working if I don't copy code from page to page about navigating to every other page.I started reading about how XAML can do navigation itself so I replaced my flyout's button code with the following:
This doesn't fire any events nor does it produce any errors or logging; I double-checked that my routes are named the same but it didn't seem to work.
I next tried using CodeBehind instead but since I'm in a
Flyout
not aPage
theNavigator()
instance wasn't accessible:Is there a way to have a MVUX model with a flyout so that I can use DI and string localization and keep all the navigating code between my pages in one component? I tried making such a class and registering it in
App.xaml.cs
but it didn't seem to work:It seems like the Flyout isn't picking up on the model like all the other pages do; I'm left with a menu that doesn't do anything.
So many things I've tried haven't worked the way it seems like they should that I'm thinking I'm taking the wrong approach here; is there a sample app using the latest Uno version that implements a few pages and navigates between them using a flyout?
Thanks for any and all help!
Beta Was this translation helpful? Give feedback.
All reactions