silverlight 自定义 鼠标 双击事件

public partial class MainPage : UserControl
    {
        public DateTime _lastClick = DateTime.Now;
        private bool _firstClickDone = false;

        public MainPage()
        {
            InitializeComponent();
            this.MouseLeftButtonDown += new MouseButtonEventHandler(MainPage_MouseLeftButtonDown);
        }

        private void MainPage_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            UIElement element = sender as UIElement;
            TimeSpan span = DateTime.Now - _lastClick;

            if (span.TotalMilliseconds > 300 || _firstClickDone == false)
            {
               //第一次点击
                _firstClickDone = true;
                _lastClick = DateTime.Now;
            }
            else
            {
                 //双击触发
                //双击代码请在这里编写

                _firstClickDone = false;
            }           
        }
    }

你可能感兴趣的:(silverlight)