Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to implement a press and hold event for a wpf Usercontrol(here am using toggle button, want to implement on this), i am implementing a copy function with this event fired... am using in C# wpf application.... please suggest me a good way to do this...
Posted
Comments
Sergey Alexandrovich Kryukov 29-Dec-14 12:08pm    
This is pretty simple, but you have to explain: press on what? :-)
The hint: you can use a timer. It's interval should define what is "long enough".
—SA
Ranjith Mameras 29-Dec-14 13:11pm    
yes i want to press and hold after some time interval there should be an event occured, there i can implement my functionality.

Thanks for you reply Sergey
Kornfeld Eliyahu Peter 29-Dec-14 13:51pm    
You didn't answered SA...Press of what? Key? Mouse?
Sergey Alexandrovich Kryukov 29-Dec-14 14:37pm    
Just do it. Use the timer.
—SA

1 solution

Some more hints:

Use this timer type: http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatchertimer%28v=vs.110%29.aspx[^].

Wind up the timer on the initial press and use only one tick, then stop the timer (http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatchertimer.stop(v=vs.110).aspx[^]). Set the property Interval (http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatchertimer.interval(v=vs.110).aspx[^]) to the time which you consider to be a time of a "long press".

Create your own even type arguments representing "long press" even. Declare the event instance in some of your UI element class; invoke this event in your handler of the timer tick event (http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatchertimer.tick(v=vs.110).aspx[^]).

The logic, which is pretty simple, is on you.

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900