0
votes

I need to bind a Command for Xamarin forms IOS. I have followed bellow code to bind command to back button. I don't want to use ViewModel.

//this code inside the constructor

 Shell.SetBackButtonBehavior(this, new BackButtonBehavior
        {
            Command = new Command(() =>
            {
                GoBack();
            }),
        });

//method for go back

 private async Task GoBack()
    {
        bool result = await Shell.Current.DisplayAlert(
            "Going Back?",
            "Are you sure you want to go back?",
            "Yes, Please!", "Nope!");

        if (result)
        {
            await Shell.Current.GoToAsync("..", true);
        }
    }

The code perfectly working for Android but not for IOS. Appreciate the quick help and Thanks in advance.

1
There isnt Back button on iOS, so I would assume you cannot bind it. I'm affraid that you will have to write a method that removes the page from Navigation Stack on iOS. - Woj
i agree with @Woj theres no any back button on ios! soo what are you exactly trying to do? - Blu
Hi ,do you mean this code of BackButtonBehavior method not works in iOS ? docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/… What is the version of Xamarin Forms used in project ? - Junior Jiang

1 Answers

0
votes

While I don't see exact documentation for this, I think it is safe to assume that this uses OnBackButtonPressed API. As such it works only on Android and only if you press the operating system back button not when you press the back button in the toolbar.