0

I am kind of new to Xamarin development. I tried to change the back button behavior with a binding command, but that didn't seem to work. This is the code for the view:

<Shell.BackButtonBehavior>
    <BackButtonBehavior Command="{Binding GoBack}"/>
</Shell.BackButtonBehavior>

And this is the code for the view model:

public CreatePasswordVM()
{
    _goBack = new Command(GoBackButton);
}
private ICommand _goBack;
public ICommand GoBack
{
    get { return _goBack; }
}
public async void GoBackButton()
{
    await Shell.Current.GoToAsync("../..");
}

When I pressed the back button, the method "GoBackButton" didn't call. I want to mention that on Android works.

  • BindingContext missing? Check [this discussion](https://forums.xamarin.com/discussion/179742/backbuttonbehavior-in-shell-not-working). [Sample in the docs](https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/shell/navigation#back-button-behavior) didn't use mvvm btw. – Shaw Nov 25 '20 at 01:50
  • No, BindingContext is not missing... Is there a problem that I used mvvm? – himynameisgarch Nov 25 '20 at 13:04
  • @himynameisgarch, I could reproduce your problem, the reason is BackButtonBehavior has not been implemented for uwp platform. I have post the source code below, please have a look. – Nico Zhu Nov 25 '20 at 14:10
  • 1
    @NicoZhu-MSFT I saw it, I already made an issue on Xamarin Forms github! Thanks! – himynameisgarch Nov 25 '20 at 14:30

1 Answers1

1

Shell BackButtonBehavior command binding not working in UWP

Derive from Xamarin Form source code. BackButtonBehavior has not implemented for UWP platform, we could find Android and IOS implementation here and here. But for uwp there is not such tracker and there is not such value in the UWP ShellRenderer. For this scenario, we suggest your post new feature request in the Xamarin Forms github.

Nico Zhu
  • 32,367
  • 2
  • 15
  • 36