让Silverlight支持"双击"事件

当前Silverlight仅支持如下五类鼠标事件:

Event Description
MouseMove Occurs when the coordinate position of the mouse pointer changes. The mouseEventArgs parameter contains input information.
MouseEnter Occurs when the mouse enters the bounding area of an object. The mouseEventArgs parameter contains input information.
MouseLeave Occurs when the mouse leaves the bounding area of an object.  The mouseEventArgs parameter is null.
MouseLeftButtonDown Occurs when the left mouse button is down. The mouseEventArgs parameter contains input information.
MouseLeftButtonUp Occurs when the left mouse button is up, following a MouseLeftButtonDown event. The mouseEventArgs parameter contains input information.

然而,有时候我们也需要实现鼠标双击事件,可以通过计算二次 MouseLeftButtonUp之间时间差来模拟,代码如下
 1  handleMouseUp:  function (sender,mouseEventArgs)
 2  {
 3       // 模拟鼠标双击事件
 4       // 即二次up之间的时间差小于300ms即为双击
 5       var  b = ( new  Date).getTime(),c = this ._timeLastLeftButtonUp;
 6       this ._timeLastLeftButtonUp = b;
 7       var  a = c && b - c < 300 ;
 8       if (a)
 9      {
10           this ._timeLastLeftButtonUp = 0 ;
11           // 双击触发的事件调用,如实现全屏显示
12           var  plugin = sender.getHost();
13              plugin.content.fullScreen  =   ! plugin.content.fullScreen;
14      }
15  },

你可能感兴趣的:(silverlight)