Navigation

Dani_S 4,501 Reputation points
2024-03-07T02:58:00.0466667+00:00

Hi,

In continue to:

https://learn.microsoft.com/en-us/answers/questions/1608562/maui-memory-raising-when-using-application-current?page=1

I have login page after login successfully I navigate to main page.

In the main page I have header ,menu on the left and footer.

When I press on menu 1 I see page 1.

In page 1 I have button command1 when pressing it I do process if I succeeded from view model I want to see the page again from scratch. loading the data again.

Another scenario I have menu 2 when pressing on command2 I want to navigate to page 3 .if the command2 done successfully other wise stay on 2.

Another scenario if I have menu 3 and press command button on view model than staying on same page.

Can you please help me and give me full code how to do it ?

Thanks in advance,

Developer technologies .NET .NET MAUI
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,126 Reputation points Microsoft External Staff
    2024-03-11T01:28:45.0533333+00:00

    Hello,

    For your needs, you can use the following techniques and documentations to implement them.

    For the menu bar on the left, it's actually a Shell Flyout, and you can set its visibility to Locked to keep it displayed.

    Locked – indicates that the flyout can't be closed by the user, and that it doesn't overlap content.

    And since the navigation is directly controlled by the shell, the need to click on the menu item to switch to the next page can be directly realized.

    refresh page 1

    For refresh operations, you need to use the RefreshView and bind its refresh state to the ViewModel to let the user know the refresh state.

    RefreshView.

    IsRefreshing, of type bool, which indicates the current state of the RefreshView.

    command button in page 2=> page 3

    Since navigation is controlled by the shell, you can use GoToAsync to navigate through routes.

    await Shell.Current.GoToAsync("//animals/monkeys");

    Code samples are provided in the examples above, which you can combine into your own projects.

    Update:

    After in-depth testing of your sample project, this issue is related to Visual Studio's Hot Reload.

    With Hot Reload enabled, each repeated click on a Menu Item will result in a 10MB increase in memory, which will eventually lead to a memory leak. If Hot Reload is turned off, the program's memory will continue to stabilize at 160Mb after fluctuations.

    You could refer to XAML Hot Reload for .NET MAUI Visual Studio to disable this feature.

    Best Regards,

    Alec Liu.


    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.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.