I have multiple windows in a wpf project. in any window, i put a control (such as button). as position of controls in all windows is same. i define a MouseLeftButt开发者_JAVA技巧onUp event for controls in all windows. with click (mouse left button up) on the control, i create and open dialog next window. for example for first window:
Window2 win2 = new Window2 ();
win2.Owner = this;
win2.ShowDialog();
but my problem:
if i do double click or triple click on the button of first window, since all position controls in all windows is same, all two or three windows opening as cascading. and i want open only one next window.
thanks for your answers
See my comment above. You may want to consider this to be "by-design", and not fix it.
If you do decide to fix it, you could implement a form of de-bouncing.
- Create some form of global state that all windows can see (such as a field in the application object, or the main window class).
- In that global state, keep the time of the last successful/correct click. Start off with
DateTime.MinValue
(or whatever it is called). - On click, grab the current time
DateTime.Now
- If the time between the current time, and the lass successful click is too short (less than your debounce time. Maybe
TimeSpan.FromMilliseconds(500)
), then don't create a new window - If the time span is longer than your debounce time, then update the last successful/correct click, and only then open the new window
Have you considered disabled the button initially and enabling a second after the form has loaded? You can do this using a timer.
精彩评论