question

shreshtavalluru-3560 avatar image
0 Votes"
shreshtavalluru-3560 asked RoyLi-MSFT commented

how to implement backward navigation functionality through pages in winui3

Using winui3 ,the backbutton should hold history of naviagtion through one page to another page ,on clicking backbutton it should navigate through pages how it was navigated through forward wihtout creating new instance in stack like mobile navigation

windows-app-sdk
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RoyLi-MSFT avatar image
0 Votes"
RoyLi-MSFT answered

Hello,

Welcome to Microsoft Q&A!


To implement what you need in your scenario, you need to make sure the rootfame handles all navigation actions, so when you click the backbutton, it can go back.

Here are the steps:

1) you need to handle the homepage_click event inside the mainWindow.cs, not in the homepage. So that you could use the rootframe object to navigate to the deletepage just like the same way you did for the homepage.

2) you need to handle the backbutton event of the deletepage inside the mainWindow.cs, so you could use the rootframe object and call the rootframe.goback() method to navigate back.

Besides, the simplest way is that do not add navigate button inside these sub pages. Handle the navigationview's iteminvoke event to navigate to different subpages when users click on the NavigationViewItem. You could easily access the rootframe to control all the navigation actions.


Thank you.


If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JeanineZhang-MSFT avatar image
0 Votes"
JeanineZhang-MSFT answered RoyLi-MSFT commented

Hi,

Welcome to Microsoft Q&A!

I suggest you could try to use the NavigationView control to provide the navigation framework for your app. If your app uses the NavigationView control, then you can use NavigationView's built-in back button.

You could refer to the Doc: Navigation history and backwards navigation for Windows apps

Best Regards,

Jeanine



If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



· 11
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@JeanineZhang-MSFT thanks for the reply,
i see above links which i have already tried https://docs.microsoft.com/en-us/windows/apps/design/basics/navigation-history-and-backwards-navigation in this i'm getting Null reference exception.

0 Votes 0 ·

@JeanineZhang-MSFT Frame rootframe=window.current.content as Frame; nullreference exception

0 Votes 0 ·
RoyLi-MSFT avatar image RoyLi-MSFT shreshtavalluru-3560 ·

@shreshtavalluru-3560 That's the document for a UWP application. It's a little different with WinUI3 application. If you want to do navigation in a WinUI3 application, you need to add a Frame object to host the pages in your MainWindow.

For example, Let's say that you've created a WinUI3 app, it contains a MainWindow, a StartPage, and many other pages (not windows,).

1) Add a Frame object in the MainWindow that is used to show the Pages, you call the Frame.Navigate() method in the MainWindow to navigate to the StartPage,
2) You could navigate to subpages like Page2, Page3... from the StartPage via the Frame.Navigate() method of the StartPage.
3) In the subpages like Page2, Page3, you could call the Frame.GoBack(); method to go back to the StartPage

1 Vote 1 ·
Show more comments