• 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))
                    {
                        //双击事件处理。。。           
                    }
            } 
  • 相关阅读:
    filecoin维基
    FIL挖矿未能幸存,中国从此再无矿业!
    区块链基础入门-经典
    JavaScript中的ReferenceError和TypeError等错误的区别
    ueditor富文本图片上传问题
    react ice tree报错type
    react 表单项动态删除,删掉的是最后一个,因为index
    react 踩坑之input框输一个字会自动失去光标
    用blob下载音乐文件
    用blob下载音频并改名
  • 原文地址:https://www.cnblogs.com/haoqi/p/3383983.html
Copyright © 2020-2023  润新知