DisplayAlert 方法在 xamarin.form 中导致崩溃

DisplayAlert Method causing crash in xamarin.form

我在我的 xamarin 表单应用程序中使用了两个条目。我想检查每当用户单击按钮时,如果这些条目为空则显示错误。目前我正在使用以下方法:

            if (string.IsNullOrEmpty(EnAirflow.Text) || string.IsNullOrEmpty(EnPressure.Text))
        {
            DisplayAlert("Error", "Please fill all required information.", "OK");

        }

代码在模拟器上的调试模式下运行良好。但是,当我将其更改为发布模式或从中创建一个 apk 文件并在物理设备上进行测试时,它会导致崩溃。 你能指导我如何解决这个问题吗?

让你点击按钮作为异步方法并像下面一样添加等待:

public async Task YourButtonClickEvent(object sender, EventArgs args)
{
        if (string.IsNullOrEmpty(EnAirflow.Text) || string.IsNullOrEmpty(EnPressure.Text))
        {
            await  DisplayAlert("Error", "Please fill all required information.", "OK");
            return;
        }
}

实际上我的问题是通过在属性中将链接选项更改为 None 来解决的。但是现在我的 apk 大小太大了。有什么办法可以减少吗?

请检查这个

Device.BeginInvokeOnMainThread(() =>
{
            DisplayAlert("Error", "Please fill all required information.", "OK");         
});