In WPF when the MouseMove event is triggered, I want to check if the left mouse key is pressed, if it’s pressed I want to do some calculation.
I have tried this:
private void Window_MouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
Calculate();
}
}
But when I left-click and hold and move the mouse around the screen the Calculate() only gets called one time (i.e when the mouse starts moving), after that no matter where I move the mouse the method does not get called.
I want the Calculate() method to get called repeatedly while the mouse is moving and while the left mouse key is pressed.
A simple test for me shows this working:
A would suspect that your
Calculatemethod is a synchronous method that’s causing problems.Try calling the method like below. This will start the calculate method in a new thread. Then the updating of the text box will happen in the original thread.