How can I implement the following in my piece of code written in WPF C#?
I have a ElementFlow control in which I have implemented a SelectionChanged event which (by definition) fires up a specific event when the control's item selection has changed.
What I would like it to do is:
- Start a timer
- If the timer reaches 2 seconds then launch a MessageBox saying ("Hi there") for example
- If the selection changes before the timer reaches 2 seconds then the timer should be reset and started over again.
This is to ensure that the lengthy action only launches if the selection has not changed within 2 seconds but I am not familiar with the DispatcherTimer feature of WPF as i am more in the know when it comes to the normal Timer of Windows Forms.
Thanks,
S.
look here is the code of how to use DispatherTimer and you can add your own logic in it. that will depends on you..
To use a DispatcherTimer:
I've figured the complete code out as such:
Try this:
In your constructor or relevant method:
And then an event handler:
Finally, to make this work, you just need to set the
hasSelectionChanged
variable when the selection has changed according to yourSelectionChanged
event.