Silverlight DoubleClickHelper 双击事件模拟类
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 SFiresoft.Util { /// <summary> /// 鼠标双击监测辅助类 /// </summary> public class DoubleClickHelper { private System.Windows.Threading.DispatcherTimer _doubleClickTimer; public static DoubleClickHelper _DoubleClickHelper = null; public static DoubleClickHelper getInstance() { if (_DoubleClickHelper == null) { _DoubleClickHelper = new DoubleClickHelper(); } return _DoubleClickHelper; } public object TargetObject { get; set; } private DoubleClickHelper() { _doubleClickTimer = new System.Windows.Threading.DispatcherTimer(); _doubleClickTimer.Interval = new TimeSpan(0, 0, 0, 0, 300); _doubleClickTimer.Tick += new EventHandler(DoubleClick_Timer); _doubleClickTimer.Stop(); } void DoubleClick_Timer(object sender, EventArgs e) { _doubleClickTimer.Stop(); } /// <summary> /// 检测当前是否为双击事件 /// /// </summary> /// <returns></returns> public bool IsDoubleClick(object targetObject) { if (object.ReferenceEquals(targetObject, this.TargetObject)) { if (_doubleClickTimer.IsEnabled) { _doubleClickTimer.Stop(); return true; } else { _doubleClickTimer.Start(); return false; } } else { _doubleClickTimer.Start(); this.TargetObject = targetObject; return false; } } } }
公司网站:
http://www.codersoft.cn
专业开发:
气象软件、监狱网上购物系统、两法衔接平台