Confirmation Dialog on back button press event Xamarin.Forms

后端 未结 6 826
北海茫月
北海茫月 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:42

        protected override bool OnBackButtonPressed()
        {
            Device.BeginInvokeOnMainThread(async() => {
                var result = await this.DisplayAlert("Alert!", "Do you really want to exit?", "Yes", "No");
                if (result) await this.Navigation.PopAsync(); // or anything else
            });
    
            return true;
        }
    

提交回复
热议问题