我在ListBoxItem
. 所以当我拿着一个项目时,它会直接进入函数,但它会在被触发两次时出现。
private async void OutersAndContactInTel_Holding(object sender, HoldingRoutedEventArgs e)
{
try
{
FrameworkElement element = (FrameworkElement)e.OriginalSource;
if (element.DataContext != null && element.DataContext is Contact)
{
Contact selectedContact = (ImOutContact)element.DataContext;
if (selectedContact.IsOuter)
{
MessageDialog msgToAddContact = new MessageDialog("Voulez-vous vraiment suivre " + selectedContact.Pseudo + " ?");
msgToAddContact.Commands.Add(new UICommand("Oui", (UICommandInvokedHandler) =>
{
AddContactProcess(selectedContact);
}));
msgToAddContact.Commands.Add(new UICommand("Non"));
this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => msgToAddContact.ShowAsync());
}
else
{
MessageDialog msgToInviteContact = new MessageDialog("Envoyez une invitation à l'utilisation de l'application par sms à " + selectedContact.NomPrenom + " ?");
msgToInviteContact.Commands.Add(new UICommand("Oui", (UICommandInvokedHandler) =>
{
SendSmsToInvite(selectedContact);
}));
msgToInviteContact.Commands.Add(new UICommand("Non"));
await msgToInviteContact.ShowAsync();
}
}
}
catch (Exception ex)
{
MessageDialog errorMessage = new MessageDialog(CustomDialogMessage.getMessageContent(CustomDialogMessage.ERROR_MESSAGE));
this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => errorMessage.ShowAsync());
}
}
当我在该函数的末尾显示一个MessageDialog
msgToAddContact时,它被触发了两次,它也MessageDialog
显示了两次。
如果第一个MessageBox.showAsync
没有完成,它会崩溃,因为不可能同时显示多个MessageDialog
。
有谁知道如何阻止举行活动的第二次执行?
提前致谢!