I have a holding event on a ListBoxItem
. So When I hold an item, it enters right in the function but it appears as it's fired twice.
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());
}
}
As I'm displaying a MessageDialog
msgToAddContact at the end of that function, the fact that it's fired twice, it makes the MessageDialog
displayed twice too.
If the first MessageBox.showAsync
is not finished, it crashes because it's not possible to show multiple MessageDialog
at the same time.
Does anyone knows how to block the second execution of the holding event?
Thanks in advance!