Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logout Display alert xamarin.forms

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 the login page. I haven't managed to get this done, if I click Yes or No, both options remain in the profile page

public async void LogoutBtn(object sender, EventArgs e)
{
    var answer = await DisplayAlert("Exit", "Do you wan't to exit the App?", "Yes", "No");
    if(answer.Equals("Yes"))
    {
        Settings.FirstName = string.Empty;
        Settings.LastName = string.Empty;
        Settings.Email = string.Empty;
        await Navigation.PushAsync(new MainPage());
    }
    else
    {
        App.Current.MainPage = new Profile();
    }
}
like image 781
Janine Alexander Avatar asked Dec 15 '25 02:12

Janine Alexander


1 Answers

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
}
like image 179
SushiHangover Avatar answered Dec 16 '25 14:12

SushiHangover