Silverlight 中没有鼠标双击事件. 但是用 System.Windows.Threading.DispatcherTimer 可以模拟鼠标双击事件.
代码如下:
Xaml:
代码如下:
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
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
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