• silverlight双击事件处理


    首先添加双击处理帮助类:

        public static class DoubleClickHelper
        {
            private const long k_DoubleClickSpeed = 300;
            private const double k_MaxMoveDistance = 10;
            private static long m_LastClickTicks = 0;
            private static Point m_LastPosition;
            private static object m_LastSender;
            /// <summary>
            /// 鼠标双击事件处理。
            /// </summary>
            /// <param name="sender">类型对象</param>
            /// <param name="e">事件数据</param>
            /// <returns>bool</returns>
            public static bool IsDoubleClick(object sender, MouseButtonEventArgs e)
            {
                bool senderMatch = sender.Equals(m_LastSender);
                m_LastSender = sender;
                long clickTicks = DateTime.Now.Ticks;
                Point position = e.GetPosition(null);
                if (senderMatch)
                {
                    long elapsedTicks = clickTicks - m_LastClickTicks;
                    long elapsedTime = elapsedTicks / TimeSpan.TicksPerMillisecond;
                    double distance = position.Distance(m_LastPosition);
                    if (elapsedTime <= k_DoubleClickSpeed && distance <= k_MaxMoveDistance)
                    {
                        // Double click!
                        m_LastClickTicks = 0;
                        return true;
                    }
                }
                // Not a double click
                m_LastClickTicks = clickTicks;
                m_LastPosition = position;
                return false;
            }
            // 获取间距
            private static double Distance(this Point pointA, Point pointB)
            {
                double x = pointA.X - pointB.X;
                double y = pointA.Y - pointB.Y;
                return Math.Sqrt(x * x + y * y);
            }
        }

    页面代码:

    <sdk:DataGrid MouseLeftButtonUp="dg_MouseLeftButtonUp" ></sdk:DataGrid> 

    后台代码这样写:

            private void dg_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
            {
                if (dg.SelectedItem != null)
                {
                    if (DoubleClickHelper.IsDoubleClick(sender, e))
                    {
                        //双击事件处理。。。           
                    }
            } 
  • 相关阅读:
    CSS设置滚动条样式
    js深拷贝实现
    JMeter+Ant+Jenkins接口自动化测试框架(Windows)
    jmeter和JDK安装教程(Windows)
    jmeter目录结构含义
    jmeter常用组件
    selenium高亮显示定位到的页面元素
    Python 函数中箭头 (>)的用处
    code first
    AutoFac自动注入的实现过程
  • 原文地址:https://www.cnblogs.com/haoqi/p/3383983.html
Copyright © 2020-2023  润新知