Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

How do you properly implement a OnBackButtonPressed override with async functions?

$
0
0

We're a little confused as to how to mix Xamarin.Forms page functions like DisplayAlert and the OnBackButtonPressed override since one is async and the other is not.

We tried this, but the DisplayAlert doesn't appear since there is no await in front of it, but if we add it, it doesn't compile because the overridden event expects the return parameter to be bool, not Task<bool>.

protected override bool OnBackButtonPressed (){
    if (this.Detail.GetType().ToString() == "Klaim.HomePage") {
        Task<bool> action = DisplayAlert ("Quitter?", "Voulez-vous quitter l'application?", "Oui", "Non");
        if (action.Result) 
            DisplayAlert("debugvalue", "TRUE", "ok");
    } else {
        ViewModel.NavigateTo (new HomePage(new HomeViewModel()));
    }
}

Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>