0
我嘗試在觸摸(MouseDown)和最大1秒鐘期間加載類似「holdFunction」的函數。MouseDown和計時器的組合
所以當用戶嘗試觸摸並保持一秒鐘我必須調用該函數,這與mouseUp無關。
也許我一定要結合這些:
private DateTime dtHold;
private void EditProduct_MouseDown(object sender, MouseButtonEventArgs e)
{
dtHold = DateTime.Now;
}
private void EditProduct_MouseUp(object sender, MouseButtonEventArgs e)
{
TimeSpan interval = TimeSpan.FromSeconds(1);
if (DateTime.Now.Subtract(dtHold) > interval)
{
//HoldFunction();
}
}
和
System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
private void EditProduct_MouseDown(object sender, MouseButtonEventArgs e)
{
dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
dispatcherTimer.Interval = new TimeSpan(0, 0, 0,1,0);
dispatcherTimer.Start();
}
private int _sec = 0;
private void dispatcherTimer_Tick(object sender, EventArgs e)
{
_sec = _sec + 1;
if (_sec == 2)
{
dispatcherTimer.Stop();
{
//HoldFunction();
}
_sec = 0;
return;
}
}
是的,這工作完美,謝謝你:) – AliMajidiFard9