我的uwp应用程序中有一个数据透视控件。在pivot_selectionchanged事件中,我已写入显示消息对话框。
在我点击了枢轴项目后生成uwp应用程序包后,应该显示一些警告消息对话框,但是在那时应用程序崩溃时它没有显示。 这仅适用于某些机器。 任何人都可以知道原因吗?
我写的代码是
private void OpenBillPivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
bool Isreturn = false;
bool IsExchange = false;
Isreturn = checkUserPermission(Constants.Return);
IsExchange = checkUserPermission(Constants.Exchange);
if (Application.Current.Resources[Constants.RETURNS].ToString() == Constants.FALSE_CAMELCASE)
Isreturn = false;
else
Isreturn = true;
if (Application.Current.Resources[Constants.EXCHANGES].ToString() == Constants.FALSE_CAMELCASE)
IsExchange = false;
else
Isreturn = true;
if ((txtblStatus.Text == "Cancelled" || txtblStatus.Text=="Draft") && (OpenBillPivot.SelectedIndex == 1 || OpenBillPivot.SelectedIndex == 2 || OpenBillPivot.SelectedIndex == 3))
{
TransactionDetails.Visibility = Visibility.Collapsed;
ReturnDetails.Visibility = Visibility.Collapsed;
ExchangeDetails.Visibility = Visibility.Collapsed;
//SimpleMessageDialog(ResourceLoader.GetForCurrentView().GetString("PLEASE_CLEAR_THE_BILL"), ResourceLoader.GetForCurrentView().GetString("ALERT"));
}
else if (OpenBillPivot.SelectedIndex == 2)
{
if ((txtblStatus.Text == "Pending" && txtblBillDue.Text != Constants.ZERO))
{
ReturnDetails.Visibility = Visibility.Collapsed;
ExchangeDetails.Visibility = Visibility.Collapsed;
SimpleMessageDialog(ResourceLoader.GetForCurrentView().GetString("PLEASE_CLEAR_THE_BILL"), ResourceLoader.GetForCurrentView().GetString("ALERT"));
}
else
{
if (!Isreturn)
{
ReturnDetails.Visibility = Visibility.Collapsed;
SimpleMessageDialog("Access Denied", ResourceLoader.GetForCurrentView().GetString("ALERT"));
}
else
ReturnDetails.Visibility = Visibility.Visible;
}
}
和消息对话代码:
private async void SimpleMessageDialog(string Message, string Title)
{
MessageDialog dialog = new MessageDialog(Message, Title);
dialog.CancelCommandIndex = 1;
await dialog.ShowAsync();
}
答案 0 :(得分:1)
可能是因为您实际上没有等待消息显示,将返回类型从void更改为Task:
private async Task SimpleMessageDialog(string Message, string Title)
{
MessageDialog dialog = new MessageDialog(Message, Title);
dialog.CancelCommandIndex = 1;
await dialog.ShowAsync();
}
并等待它:
await SimpleMessageDialog(ResourceLoader.GetForCurrentView().GetString("PLEASE_CLEAR_THE_BILL"), ResourceLoader.GetForCurrentView().GetString("ALERT"));
您还需要将方法更改为异步:
private async void OpenBillPivot_SelectionChanged...