首页 > 代码库 > Silverlight 鼠标双击 事件
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 onm ouseDbClick(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 onm ouseDbClick(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 onm ouseLeftButtonDown(object sender, MouseButtonEventArgs e) { } public void onm ouseLeftButtonUp(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; } } }}
Silverlight 鼠标双击 事件
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。