如何在wpf控件上实现长按事件? [英] How to implement a long press event on wpf control?

查看:699
本文介绍了如何在wpf控件上实现长按事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为wpf Usercontrol实现一个按住事件(这里使用切换按钮,想在此实现),我正在实现一个复制函数,这个事件被触发了...我在C#wpf应用程序中使用。 ...请建议我这样做的好方法...

解决方案

更多提示:



使用此计时器类型: http:/ /msdn.microsoft.com/en-us/library/system.windows.threading.dispatchertimer%28v=vs.110%29.aspx [ ^ ]。



在初始按下时关闭计时器并仅使用一个刻度,然后停止计时器( http://msdn.microsoft.com/en-us/library/s ystem.windows.threading.dispatchertimer.stop(v = vs.110).aspx [ ^ ])。设置属性 Interval http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatchertimer.interval(v = vs.110)的.aspx [<一个href =http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatchertimer.interval(v=vs.110).aspx\"target =_ blanktitle =New Window> ^ ])到你认为是长按的时间。



创建你自己的偶数类型参数代表长按 甚至。在一些UI元素类中声明事件实例;在计时器tick事件的处理程序中调用此事件( http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatchertimer.tick(v = vs.110).aspx [ ^ ] )。



这个逻辑非常简单,就在你身上。



- SA

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...

解决方案

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


这篇关于如何在wpf控件上实现长按事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆