I am working on a WPF application where i handled a mouse down event which eventually shows up MessageBox.. But after MessageBox appears on mouseDown, it eats up corresponding MouseUp event of a control.
Scenario can be easily reproduced by simply handling MouseDown and MouseUP event in WPF window as:-
private void Window_MouseDown(object sender, MouseButtonEventArgs e)
{
MessageBox.show("Hello, Mouse down");
}
private void Window_MouseUP(object sender, MouseButtonEventArgs e)
{
MessageBox.show("Hello, Mouse Up");
}
MouseUp message is never shown, once messagebox appears on MouseDown event.
What about initializing a new instance of System.Threading.Thread
to call the MessageBox
so that the main user interface thread would not be interrupted by the prompt?
Example
private void Window_MouseDown(object sender, MouseEventArgs e)
{
Thread mythread = new Thread(() => MessageBox.Show("Hello, Mouse Down")); //Initialize a new Thread to show our MessageBox within
mythread.Start(); //Start the thread
}
private void Window_MouseUP(object sender, MouseEventArgs e)
{
Thread mythread = new Thread(() => MessageBox.Show("Hello, Mouse Up")); //Initialize a new Thread to show our MessageBox within
mythread.Start(); //Start the thread
}
Screenshot
Thanks,
I hope you find this helpful :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With