注销显示警报 xamarin.forms [英] Logout Display alert xamarin.forms

查看:20
本文介绍了注销显示警报 xamarin.forms的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试允许用户使用 DisplayAlert 确认注销.如果他们点击否",它应该保留在他们的个人资料页面中,否则他们应该被重定向回登录页面.我还没有完成,如果我点击是或否,这两个选项都保留在个人资料页面中

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();
    }
}

推荐答案

DisplayAlert 返回一个布尔值 (true/false):

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
}

这篇关于注销显示警报 xamarin.forms的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆