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
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
}
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