本实例是基于Canvas增加双击事件

public class RevitCanvas : Canvas
{
public RevitCanvas()
{
_oncetime = long.MaxValue;
Focusable = true;
this.AddHandler(Canvas.PreviewMouseDownEvent, new MouseButtonEventHandler(OnMouseDown)); //这里是使用使用双击事件哦
this.AddHandler(RevitCanvas.MouseDoubleClick, new RoutedEventHandler(OnMouseDoubleClick));
} public static RoutedEvent MouseDoubleClick = EventManager.RegisterRoutedEvent("MouseDoubleClick", RoutingStrategy.Bubble, typeof(MouseButtonEventHandler), typeof(RevitCanvas)); protected void OnMouseDown(object sender, MouseButtonEventArgs e)
{
base.OnMouseDown(e); //双击,两次单机距离不超过4像素,时间再0.5秒以内视为双击
Point p = e.GetPosition(this);
long time = DateTime.Now.Ticks;
if (Math.Abs(p.X - _oncePoint.X) < && Math.Abs(p.Y - _oncePoint.Y) < && (time - _oncetime < ))
{
this.RaiseEvent(new RoutedEventArgs(RevitCanvas.MouseDoubleClick));//此处促发双击事件
}
_oncetime = time;
_oncePoint = p;
} private void OnMouseDoubleClick(object sender, RoutedEventArgs e)
{
//我是双击事件哦
} private Point _startPoint;
private long _oncetime;
private Point _oncePoint;
}

双击事件使用:

        this.AddHandler(RevitCanvas.MouseDoubleClick, new RoutedEventHandler(OnMouseDoubleClick));

        private void OnMouseDoubleClick(object sender, RoutedEventArgs e)
{
//我是双击事件哦
}

WPF实现双击事件MouseDoubleClick的更多相关文章

  1. wpf ListBox 双击事件时在子项添加Style 确保选中

    <ListBox ItemTemplate="{StaticResource CardPictureTemplate}" VirtualizingPanel.CacheLen ...

  2. WPF ListboxItem 双击事件 Command绑定

    <ListBox x:Name="Lb" HorizontalAlignment="Left" Height="600" Vertic ...

  3. C# Note16: wpf window 中添加enter和双击事件

     一.添加回车(enter)事件 在C#编程时,有时希望通过按回车键,控件焦点就会自动从一个控件跳转到下一个控件进行操作. 以用户登录为例,当输入完用户名和密码后, 需要点击登录按钮,而登录按钮必须获 ...

  4. WPF中如何将ListViewItem双击事件绑定到Command

    今天的博客将介绍如何实现ListViewItem双击事件绑定到ViewModel中的Command.实现方法借助了Style中的EventSetter,请看下面的详细代码: <ListView ...

  5. WPF 之 鼠标双击事件

    由于WPF中没有鼠标的双击事件,因而只能通过MouseDown事件来模拟.当连续的两次MouseDown事件的时间间隔,没有超过一个设定的时间阈值时,就计算为一个双击事件,并作相应的处理. 利用WPF ...

  6. WPF: 在 MVVM 设计中实现对 ListViewItem 双击事件的响应

    ListView 控件最常用的事件是 SelectionChanged:如果采用 MVVM 模式来设计 WPF 应用,通常,我们可以使用行为(如 InvokeCommandAction)并结合命令来实 ...

  7. 【WPF】图片按钮的单击与双击事件

    需求:ListBox中的Item是按钮图片,要求单击和双击时触发不同的事件. XAML中需要引入System.Windows.Interactivity.dll xmlns:i="clr-n ...

  8. WPF - 善用路由事件

    原文:WPF - 善用路由事件 在原来的公司中,编写自定义控件是常常遇到的任务.但这些控件常常拥有一个不怎么好的特点:无论是内部还是外部都没有使用路由事件.那我们应该怎样宰自定义控件开发中使用路由事件 ...

  9. WPF DataGrid 双击行 获得绑定数据

    原文:WPF DataGrid 双击行 获得绑定数据 1)增加事件 2)增加对象获取 1)事件代码 Datagrid 增加事件 MouseDoubleClick="dataGrid_Mous ...

随机推荐

  1. 根据第三方提供的webservice地址获取文件信息

    import org.apache.axis.client.Call; import org.apache.axis.client.Service; import org.apache.axis.en ...

  2. 菜鸟学Java(十七)——Jboss瘦身

    大家在用Jboss的时候可能跟我一样,觉得Jboss启动实在太慢!比起Tomcat几乎秒启的速度,Jboss几乎让人无法忍受.加上本人电脑配置比较低,Jboss启动最快的时候也是一分多钟,慢的时候四分 ...

  3. Theories of Deep Learning

    https://stats385.github.io/readings Lecture 1 – Deep Learning Challenge. Is There Theory? Readings D ...

  4. Linux的sysctl 命令参数详解

    Linux内核通过/proc虚拟文件系统向用户导出内核信息,用户也可以通过/proc文件系统或通过sysctl命令动态配置内核.比如,如果我们想启动NAT,除了加载模块.配置防火墙外,还需要启动内核转 ...

  5. 每日英语:How to Solve India's Huge Food Wastage

    India is one of the world’s  largest producers of fruits and vegetables, but a third of its produce ...

  6. 使用终端执行.app程序 for mac

    背景:打开Eclipse闪退,需要查看错误日志 问题:使用Terminal执行 ./Eclipse.app时,提示“no such file or directory” 解决方案:执行./Applic ...

  7. c++ primer读书笔记之c++11(四)

    1  带有作用域的枚举 scoped-enumeration 相信大家都用过枚举量,都是不带有作用域的,在头文件中定义需要特别注意不要出现重名的情况.为了解决这种问题,c++11提供了带作用于的枚举. ...

  8. Android getWindow().setFlags方法

    //设置窗体全屏 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams ...

  9. LeetCode: Merge Two Sorted Lists 解题报告

    Merge Two Sorted Lists Merge two sorted linked lists and return it as a new list. The new list shoul ...

  10. Linux下字符集的安装

    目前环境中经常会遇到编码转化的问题,UTF-8跟GB2312也有问题.只得在Linux上安装GB2312(在Linux操作系统上又称zh_CN.GB2312)的字符集,具体请看下文. Linux下几个 ...