1
votes

Intro I have a WPF application. When i click/double click on a button to show next screen, this is captured with both MouseLeftButtonDown and MouseLeftButtonUp. - MouseLeftButtonDown is making the button darker - MouseLeftButtonUp is sending me to next screen

The problem: If i "spam" or sometimes just click 2-3 (we say 3 times in this case) times on the button, it's start loading the next screen. When the next screen is shown, two mouse clicks is left in the queue and if the mouse is over another new button at the second screen, this is clicked on.

I tried with stuff like:

    void LayoutRoot_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
    {
        Mouse.OverrideCursor = Cursors.Wait;
        if (this.IsVisible && this.IsLoaded)
            OnButtonPatient();
    }

but both properties is set to true. I guess thats right since i can see the button when the mouse event triggers. The events can be explained like:

  1. 3 mouse clicks
  2. mouse cursor = waiting cursor
  3. next screen is loaded
  4. mouse cursor = normal
  5. mouse cursor = waiting cursor
  6. next button is clicked

How can i handle this? I dont want mouse event that happend on a previously screen follow on to my next screen. Greetings!

2
The solution in this case was to simple change the behaviour of the user. The problem occured when the used "double clicked" on buttons. The buttons should be seen as "links" or webpage buttons which you only click once. We added a color to the selected item which indicate that the item they are going to click on is selected and most people will only click once at that stage. Before did some people thought theey had to do the double click to first select then open. - HappySoftwareDeveloper

2 Answers

1
votes

I tried a simple example using StackPanel as control. Although I am not sure why you are not using Button Click event if you are using a button (Why move on ButtonUp?)

private int count = 0;
        private void StackPanel_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (count == 0 && (sender as StackPanel).IsMouseOver)
            {
                Mouse.OverrideCursor = Cursors.Wait;
                count++;
            }

            e.Handled = true;
        }

        private void StackPanel_OnMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (count == 1 && (sender as StackPanel).IsMouseOver)
            {
                Mouse.OverrideCursor = Cursors.Arrow;
                count++;
            }

            e.Handled = true;
        }
0
votes

I would suggest checking the IsMouseOver property on your first window/screen when the MouseUp event fires. This would let you filter out events where the new window is blocking the first.

void LayoutRoot_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
    Mouse.OverrideCursor = Cursors.Wait;
    if (this.IsVisible && this.IsLoaded && this.IsMouseOver)
        OnButtonPatient();
}