我想禁用一個按鈕- 爲了防止雙擊:在平板電腦上你推一次,它點擊兩次,這是我知道的最簡單的破解 -短期,但我注意到/調試的時間間隔可能是在實踐中過長; 50毫秒vs> 2秒。爲什麼DispatcherTimer Tick事件沒有按時發生?
只有一行啓動計時器,一行停止。隨機的間隔是50毫秒或更大。沒有CPU消耗,我只需用鼠標點擊我的4核心桌面PC上的按鈕。
會是什麼原因?
DispatcherTimer timerTouchDelay = new DispatcherTimer();
protected override void OnMouseDown(MouseButtonEventArgs e)
{
//Init
if (timerTouchDelay.Interval.Milliseconds == 0)
{
timerTouchDelay.Tick += new EventHandler(timerTouchDelay_Tick);
timerTouchDelay.Interval = new TimeSpan(0, 0, 0, 0, 50); //ms
}
if(timerTouchDelay.IsEnabled)
return;
timerTouchDelay.Start();
HandleKeyDown();
base.OnMouseDown(e);
}
private void timerTouchDelay_Tick(object sender, EventArgs e)
{
timerTouchDelay.Stop();
}
你不能在OnMouseDown函數中禁用它,並在第一個timerTouchDelay_Tick上啓用它。 – CodingBarfield