Silverlight 滑鼠雙擊 事件

來源:互聯網
上載者:User

標籤:des   style   blog   http   color   io   os   ar   for   

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>
View Code

後台代碼

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

實現雙擊的介面代碼

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

實現雙擊的代碼

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

 

Silverlight 滑鼠雙擊 事件

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.