3
votes

Is there a way in Xamarin.Forms to press the back button from code? I tried to call OnBackButtonPressed and SendBackButtonPressed but this does not work. The OnBackButtonPressed Event is called but the back action does not perform.

Call OnBackButtonPressed:

if (_currentQuestionnaireGroup != null)
   await RefreshDataAsync();
else
{
   App.QuestionnaireOverviewPage.IsDirty = true;
   this.OnBackButtonPressed();
}

Event:

protected override bool OnBackButtonPressed()
{
    if (_questionnaireHandler != null)
        App.QuestionnaireOverviewPage.IsDirty = true;

    return true;
}
1

1 Answers

-1
votes

Sorry for the poor english

In your Event, change return true; for return base.OnBackButtonPressed();.

When you return true, the action 'back' is canceled at device.