WPF ListBoxItem双击、单击事件分别处理

2021-02-11 20:17

阅读:671

标签:start   tar   hand   nbsp   down   eve   invoke   eset   double   

 1      private void listBox_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
 2         {            
 3             var element = (FrameworkElement)sender;
 4             if (e.ClickCount == 1)
 5             {
 6                 var timer = new System.Timers.Timer(500);
 7                 timer.AutoReset = false;
 8                 timer.Elapsed += new ElapsedEventHandler((o, ex) => element.Dispatcher.Invoke(new Action(() =>
 9                 {
10                     var timer2 = (System.Timers.Timer)element.Tag;
11                     timer2.Stop();
12                     timer2.Dispose();
13                     UIElement_Click(element, e);
14                 })));
15                 timer.Start();
16                 element.Tag = timer;
17             }
18             if (e.ClickCount > 1)
19             {
20                 var timer = element.Tag as System.Timers.Timer;
21                 if (timer != null)
22                 {
23                     timer.Stop();
24                     timer.Dispose();
25                     UIElement_DoubleClick(sender, e);
26                 }
27             }
28         }
29 
30         private void UIElement_Click(object sender, MouseButtonEventArgs e)
31         {
32             
33         }
34 
35         private void UIElement_DoubleClick(object sender, MouseButtonEventArgs e)
36         {
37             
38         }

 

WPF ListBoxItem双击、单击事件分别处理

标签:start   tar   hand   nbsp   down   eve   invoke   eset   double   

原文地址:https://www.cnblogs.com/Eric-Hwang/p/8487209.html


评论


亲,登录后才可以留言!