Logout Display alert xamarin.forms

前端 未结 2 1252
野的像风
野的像风 2021-01-15 17:36

I\'ve been trying to allow a user to confirm logout by using DisplayAlert. If they click \"No\" it should remain in their profile page else they should be redirected back to

相关标签:
2条回答
  • 2021-01-15 17:59

    DisplayAlert returns a boolean (true / false):

    var answer = await DisplayAlert("Exit", "Do you wan't to exit the App?", "Yes", "No");
    if (answer)
    {
        // User choose Yes
    }
    else
    {
        // User choose No
    }
    
    0 讨论(0)
  • 2021-01-15 18:15

    As SushiHangover point out DisplayAlert returns a bool. You should replace it with DisplayActionSheet or stay with it and correct the if.

    Your else clause seems to be incorrect.
    If the user choose No you should do nothing. Why do you assign a new Profile to the MainPage?

    Beside that, it seems that you have problems with navigation in general. Looking at your code, logout will push a page on a top of the executing page. Seems a bit weird. I would recommend to get familiar wit the Navigation topic firs of all:
    Official doc
    There is a free course on Xamarin University on Navigation

    0 讨论(0)
提交回复
热议问题