Rasanjana N
Rasanjana N

Reputation: 1400

How to Hide/Handle back button in C# UWP App frame

I have a UWP application and it has a workflow of few steps.

  1. Step 1
  2. Step 2
  3. Step 3
  4. Step 4

Assuming Step 4 as the last step, I want to navigate to Step 2 (NOT Step 3) on Back Button click in last step (Step 4).

Step 4 -> (click back button) -> navigate to Step 2

How can I handle the backbutton click event on my ViewModel?

OR

How can I hide the Back Button on my ViewModel?

So far, I have tried the following on the constructor of my ViewModel.

SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed;
SystemNavigationManager.GetForCurrentView().BackRequested += (s, e) =>
{
   // Handle the Back pressed                
   NavigateToStep2();
};

Upvotes: 0

Views: 382

Answers (1)

Xie Steven
Xie Steven

Reputation: 8601

Previously, UWP apps used AppViewBackButtonVisibility for backwards navigation. The API will continue to be supported to ensure backward compatibility, but we no longer recommend relying on AppViewBackButtonVisibility. Instead, your app should draw its own in-app back button. See Navigation history and backwards navigation for UWP apps for more information.

According to your description, your navigation process is highly customized. You need to make your own navigation service. In your app, you also need to make your own in-app back button and bind the command to your ViewModel's navigation command.

I have used the Template10 in my project. It has implemented a NavigationService. I directly make my ViewModels inherit its ViewModelBase class to use its navigation service. It's very convenient. You could check the Template10 source code for more details. It would be helpful to you to make your own navigation service. Or you could also directly use Template10 NavigationService.

Upvotes: 1

Related Questions