博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Silverlight 鼠标双击 事件
阅读量:6434 次
发布时间:2019-06-23

本文共 3189 字,大约阅读时间需要 10 分钟。

Silverlight 双击事件例子

View Code

后台代码

using System;using System.Collections.Generic;using System.Linq;using System.Net;using System.Windows;using System.Windows.Controls;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Animation;using System.Windows.Shapes;namespace MouseDbClick{    public partial class MainPage : UserControl,IMouseDbClick    {        MouseDbClickHander hander = null;        public MainPage()        {            InitializeComponent();            hander = new MouseDbClickHander(this);            lbTest.MouseLeftButtonDown += new MouseButtonEventHandler(lbTest_MouseLeftButtonDown);            lbTest.MouseLeftButtonUp += new MouseButtonEventHandler(lbTest_MouseLeftButtonUp);            string[] str = {
"a","b","c","d" }; lbTest.ItemsSource = str; } void lbTest_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { hander.OnMouseLeftButtonUp(sender, e); } void lbTest_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { hander.OnMouseLeftButtonDown(sender, e); } #region IMouseDbClick 成员 public void onMouseDbClick(object sender, MouseButtonEventArgs e) { string msg = lbTest.SelectedItem as string; MessageBox.Show(msg); } #endregion }}
View Code

实现双击的接口代码

using System;using System.Net;using System.Windows;using System.Windows.Controls;using System.Windows.Documents;using System.Windows.Ink;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Animation;using System.Windows.Shapes;namespace MouseDbClick{    public interface IMouseDbClick    {        void onMouseDbClick(object sender, MouseButtonEventArgs e);    }}
View Code

实现双击的代码

using System;using System.Net;using System.Windows;using System.Windows.Controls;using System.Windows.Documents;using System.Windows.Ink;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Animation;using System.Windows.Shapes;namespace MouseDbClick{    public class MouseDbClickHander    {        public DateTime lastClick = DateTime.Now;        private bool firstClick = false;        private IMouseDbClick _mouseDbClick;        // Methods        public MouseDbClickHander(IMouseDbClick mouseDbclick)        {            this._mouseDbClick = mouseDbclick;        }        public void OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)        {                    }        public void OnMouseLeftButtonUp(object sender, MouseButtonEventArgs e)        {            //UIElement ui = sender as UIElement;            TimeSpan span = DateTime.Now - lastClick;            if (span.TotalMilliseconds < 40 || firstClick == false)            {                firstClick = true;                lastClick = DateTime.Now;            }            else            {                this._mouseDbClick.onMouseDbClick(sender, e);                firstClick = false;            }        }    }}
View Code

 

到了Silverlight5.0后鼠标事件中有一个ClickCount属性,可以判断是否是双击。

转载于:https://www.cnblogs.com/ZJ199012/p/4021619.html

你可能感兴趣的文章
servlet单实例多线程模式
查看>>
Keras Data augmentation(数据扩充)
查看>>
VTK计算网格模型上的最短路径
查看>>
open-falcon的邮件报警
查看>>
iOS9的几个新关键字(nonnull、nullable、null_resettable、__null_unspecified)
查看>>
GraphQL入门2
查看>>
可以落地的DDD到底长什么样?
查看>>
使用 Content-Encoding: br 替换 Content-Encoding: gzip
查看>>
【Linux】cp命令
查看>>
基于matplotlib的数据可视化 - 热图imshow
查看>>
linux编译安装mysql5.1.x
查看>>
Tensorflow get_variable和Varialbe的区别
查看>>
CSS魔法堂:那个被我们忽略的outline
查看>>
学习ASP.NET Core Razor 编程系列十八——并发解决方案
查看>>
[翻译]pytest测试框架(二):使用
查看>>
Java-线程间通信小结
查看>>
PHPUnit简介及使用(thinkphp5的单元测试安装及使用)
查看>>
人工智能热门图书(深度学习、TensorFlow)免费送!
查看>>
照片与本人严重不符
查看>>
编码(2)从字节理解Unicode(UTF8/UTF16)
查看>>