public class Tools
{
//雙擊事件定時器
private static DispatcherTimer _timer;
//是否單擊過一次
private static bool _isFirst;
static Tools()
{
_timer = new DispatcherTimer();
_timer.Interval = new TimeSpan(0, 0, 0, 0, 400);
_timer.Tick += new EventHandler(_timer_Tick);
}
/// <summary>
/// 判斷是否雙擊
/// </summary>
/// <returns></returns>
public static bool IsDoubleClick()
{
if (!_isFirst)
{
_isFirst = true;
_timer.Start();
return false;
}
else
{
return true;
}
}
//間隔時間
static void _timer_Tick(object sender, EventArgs e)
{
_isFirst = false;
_timer.Stop();
}
}
然後再單擊事件中調用即可
private void Hyperlink_Click(object sender, RoutedEventArgs e)
{
if (Tools.IsDoubleClick())
{
Debug.WriteLine("double click");
}
else
{
Debug.WriteLine("click");
}
}
在使用有些控件的時候發現沒有MouseDoubleClick事件,只能手動添加一個