0
我的应用程序使用ContentDialog作为插入数据的手段。换一种说法;数据表单是一个ContentDialog。在验证用户输入过程中,应用程序应通过使用MessageDialog向用户提示任何错误。但是,解雇MessageDialog也会解散ContentDialog。UWP阻止MessageDialog关闭父ContentDialog
这里是代码的块时,将显示警告:
private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
{
//save item
ValidateForm();
}
private void ContentDialog_SecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
{
}
private async void ValidateForm()
{
//Ensure all fields are filled
String barcode = BarcodeText.Text.Trim();
String desc = DescText.Text.Trim();
String cost = CostText.Text.Trim();
String price = PriceText.Text.Trim();
String stock = StockText.Text.Trim();
if(barcode.Equals(String.Empty) || desc.Equals(String.Empty) ||
desc.Equals(String.Empty) || cost.Equals(String.Empty) ||
price.Equals(String.Empty) || stock.Equals(String.Empty))
{
var dialog = new MessageDialog("Please fill in all fields");
await dialog.ShowAsync();
return;
}
//check uniqueness of the barcode
}
我应该怎么做,以防止警报从关闭父ContentDialog?
您还需要考虑推迟对'ContentDialogButtonClickEventArgs'因为你直到异步操作完成后才设置'Cancel'。 –
谢谢@RaymondChen。我已将它添加到示例代码中。 –