首页 > 解决方案 > 单击警报外部时如何限制显示警报的关闭

问题描述

我正在将 xamarin.forms 用于 Android 应用程序,我需要在左侧显示警报,在右侧显示 YES 和 NO。我可以管理它,将 YES 交换为 NO 并将 NO 交换为 YES,但是当默认单击警报之外时,它被视为 YES。

我怎样才能做到这一点?

标签: xamarin.formsalertdisplay

解决方案


我使用了类似的东西,它工作得很好,尽管我注意到它可能不是面向未来的。如果用户没有单击“是”,则显示将消失而无需执行任何其他操作。

bool continue_logout = false;
try
{
    continue_logout = await DisplayAlert("Logout", "If you logout, you also clear the cache of all data. Are you sure you want to continue?", "Yes", "No");
    if (continue_logout)
    {
        // Clean up stuff and clear out user settings
    }
}
catch {

}
finally
{
    if (continue_logout)    
        App.Current.MainPage = new NavigationPage(new LoginPage());
}

推荐阅读