Confirmation Dialog on back button press event Xamarin.Forms

后端 未结 6 828
北海茫月
北海茫月 2020-12-14 19:16

I am stuck at one point in Xamarin.Forms application

On Back button press simply I want to ask user to confirm whether he really wants to exit or not, \"OnBackButton

6条回答
  •  一个人的身影
    2020-12-14 19:38

    Easy way to override hardware back button and show a confirmation dialog box to user

    protected override bool OnBackButtonPressed()
    {
        Device.BeginInvokeOnMainThread(async () =>
        {
            if (await DisplayAlert("Alert", "Are you sure you want to go back ?", "Yes", "No"))
            {
                base.OnBackButtonPressed();
    
                await Navigation.PopAsync();
             }
        });
    
        return true;
    }
    

提交回复
热议问题