Vérifiez-vous l'événement MouseUp?
Est-ce que ce que vous dites si l'utilisateur appuie sur le bouton de la souris pendant 2 secondes pour afficher un menu contextuel? Ce que je ferais sur l'événement MouseDown créer un thread séparé en attente pour les 2 secondes
Si l'événement MouseUp est déclenché avant son expiration, ne faites rien, sinon faites l'événement.
// This event will be used for tracking if the MouseUp has been received
private System.Threading.AutoResetEvent _stopTrigger;
private void OnMouseDown(object sender, MouseButtonEventArgs e)
{
if (this._stopTrigger == null)
{
this._stopTrigger = new System.Threading.AutoResetEvent(false);
}
Action popupProcess = new Action(this.ShowPopupAfterTime);
// Make the Popup process on a separate thread
popupProcess.BeginInvoke(null, null);
}
private void OnMouseUp(object sender, MouseButtonEventArgs e)
{
if (this._stopTrigger != null)
{
// Sends the signal to the ShowPopupAfterTime that it should NOT display the pop up
// IIt will make WaitOne return true and not go into the if statement
this._stopTrigger.Set();
}
}
private void ShowPopupAfterTime()
{
// Will enter the if after 2 seconds
if (!this._stopTrigger.WaitOne(2000))
{
// This means it has NOT be trigged thus I can display the popup
// DISPLAY POPUP
// DON"T FORGET you are on a different thread here, NOT UI thread. You will have to use the Dispatcher to get back
// to the UI thread to display the popup
}
}
Que signifie "cliquer et attendre"? Voulez-vous dire que vous maintenez le bouton de la souris, ou que vous voulez dire que vous cliquez sur un bouton, cela fait quelque chose, et après quelques secondes, il se passe quelque chose d'autre? Et que signifie "popup menu"? Un menu contextuel? –