Silverlight 鼠标双击 事件

Silverlight 双击事件例子

<UserControl x:Class="MouseDbClick.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">

    <Grid x:Name="LayoutRoot" Background="White">
        <ListBox Height="100" HorizontalAlignment="Left" Margin="12,12,0,0" Name="lbTest" VerticalAlignment="Top" Width="120" />
    </Grid>
</UserControl>

后台代码

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
    }
}

实现双击的接口代码

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);
    }
}

实现双击的代码

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;
            }
        }

    }
}

时间: 2024-10-11 18:16:11

Silverlight 鼠标双击 事件的相关文章

Qt鼠标双击事件mouseDoubleClickEvent(QMouseEvent* event)

重写mouseDoubleClickEvent(QMouseEvent event)* 1.实例:双击窗口时输出"sss" /*widget.h*/ #ifndef WIDGET_H #define WIDGET_H #include<QWidget> #include<QDebug> class Widget : public QWidget { Q_OBJECT public: Widget(QWidget* parent=0); ~Widget(){} p

IE和Chrome执行javascript对鼠标双击事件的不同响应

最近在用天地图API帮同学做点开发的工作,主要是基于天地图的API实现违法用地举报的在线地图标绘,要实现的效果如下: 由于是基于天地图API的TPolygonTool工具实现面积量测和多边形绘制功能,实现思路如下: (1)基于按钮的鼠标点击事件开启多边形标绘工具: 1 //开启/关闭违法标绘工具 2 function onClickPolyTool() { 3 var btn = document.getElementById("polyToolBtn"); 4 if (btn.val

BaseTool中鼠标双击事件获取鼠标位置的方法

ArcGISEngine的BaseTool类中提供了鼠标双击.鼠标移动.鼠标按键按下.鼠标按键弹起四种鼠标事件,但是鼠标双击事件的参数跟其他三种不一样,双击事件中没有提供鼠标位置信息. public virtual void OnDblClick(); public virtual void OnMouseDown(int Button, int Shift, int X, int Y); public virtual void OnMouseMove(int Button, int Shift

Unity 如何检测鼠标双击事件

代码如下: 1 void OnGUI(){ 2 Event e=Event.current; 3 if(e.isMouse&&(e.clickCount==2)) 4 Debug.Log("用户双击了鼠标"); 5 }

winform listbox增加鼠标双击事件

在Form.Designer.cs文件中对于listBox处理: listBox.MouseDoubleClick += new system.Windows.Forms.MouseEventHandler(listBox1_MouseDoubleClick); 在Form.cs代码文件中增加函数: private void listBox1_MouseDoubleClick(object sender, MouseEventArgs e) { int index = listBox1.Inde

WPF DataGrid 鼠标双击选中的DataGridRow及Row数据

设置DataGrid的MouseDoubleClick事件 代码 //DataGrid鼠标双击事件 Private void dataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e) { if(this.dataGrid.SelectedIndex == -1) { return; } DataGridRow row = (DataGridRow)dataGrid.ItemContainerGenerator.Contain

javascript鼠标双击时触发事件大全

javascript事件列表解说 事件 浏览器支持 解说 一般事件 onclick IE3.N2 鼠标点击时触发此事件 ondblclick IE4.N4 鼠标双击时触发此事件 onmousedown IE4.N4 按下鼠标时触发此事件 onmouseup IE4.N4 鼠标按下后松开鼠标时触发此事件 onmouseover IE3.N2 当鼠标移动到某对象范围的上方时触发此事件 onmousemove IE4.N4 鼠标移动时触发此事件 onmouseout IE4.N3 当鼠标离开某对象范围

JQuery如何实现双击事件时不触发单击事件,解决鼠标单双击冲突问题

在jQuery的事件绑定中,如果元素同时绑定了单击事件(click)和双击事件(dblclick),那么执行单击事件(click)时,不会触发双击事件(dblclick), 执行双击事件(dblclick)时却会触发两次单击事件(click). 但有时候我们希望在执行双击事件的时候不去出发单击事件,那究竟该如何实现呢? 少bb 上代码 : <!DOCTYPE html> <html lang="en"> <head> <meta charset

Python - selenium_WebDriver 鼠标键盘事件

from selenium import webdriver #引入ActionChains类 提供了鼠标的操作方法 from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.common.keys import Keys from ReadTxt_demo import readTxt import time #鼠标键盘事件 ''' ActionChains 常用方法 per