Silverlight 鼠标双击事件处理

Silverlight 中没有鼠标双击事件. 但是用 System.Windows.Threading.DispatcherTimer 可以模拟鼠标双击事件.

代码如下: 
Xaml:
 1 < UserControl  x:Class ="DoubleClick.MainPage"
 2     xmlns ="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
 3     xmlns:x ="http://schemas.microsoft.com/winfx/2006/xaml"
 4     xmlns:d ="http://schemas.microsoft.com/expression/blend/2008"  xmlns:mc ="http://schemas.openxmlformats.org/markup-compatibility/2006"  
 5     mc:Ignorable ="d"  d:DesignWidth ="640"  d:DesignHeight ="480" >
 6      < Grid  x:Name ="LayoutRoot" >
 7          < Button  Width ="100"  Height ="40"  Content ="Double Click Me"  Click ="Button_Click"   />
 8      </ Grid >
 9 </ UserControl >
10

C#:
 1  using  System;
 2  using  System.Windows;
 3  using  System.Windows.Controls;
 4  using  System.Windows.Threading;
 5 
 6  namespace  DoubleClick
 7  {
 8       public   partial   class  MainPage : UserControl
 9      {
10           private  DispatcherTimer _doubleClickTimer;
11 
12           public  MainPage()
13          {
14              InitializeComponent();
15 
16              _doubleClickTimer  =   new  DispatcherTimer() { Interval  =   new  TimeSpan( 0 0 0 0 200 ) };
17              _doubleClickTimer.Tick  +=   new  EventHandler(_doubleClickTimer_Tick);
18              _doubleClickTimer.Start();
19          }
20 
21           void  _doubleClickTimer_Tick( object  sender, EventArgs e)
22          {
23              _doubleClickTimer.Stop();
24          }
25 
26           private   void  Button_Click( object  sender, RoutedEventArgs e)
27          {
28               if  (_doubleClickTimer.IsEnabled)
29              {
30                   //  双击了
31                  _doubleClickTimer.Stop();
32                  MessageBox.Show( " Double Click Button " );
33              }
34               else
35              {
36                   //  没双击
37                  _doubleClickTimer.Start();
38              }
39          }
40      }
41  }
42 

转载于:https://www.cnblogs.com/hackerttao/archive/2009/09/26/1574370.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值