如何在Javascript中设置一个像HoverIntent一样的计时器XAML.CS

时间:2010-09-09 07:03:31

标签: c# .net xaml hoverintent

尝试根据以下代码包含hoverIntent:

private void ViewerTab_MouseLeave(object sender, MouseEventArgs e)
            {
                _mouseOverTabPanel = false;

                ChangeCurrentPanelPosition(TabPanelPosition.Bottom);
            }

            private void ViewerTab_MouseEnter(object sender, MouseEventArgs e)
            {
                _mouseOverTabPanel = true;
            }

理想情况下,ChangeCurrentPanelPosition只应在mouseleave约1秒后触发,如果mouseEnter再次显示,则计时器将清除。

1 个答案:

答案 0 :(得分:0)

这对我有用:

public DispatcherTimer myDispatcherTimer = new DispatcherTimer();

private void ViewerTab_MouseLeave(object sender, MouseEventArgs e)
{
    myDispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 1000);
    myDispatcherTimer.Tick += new EventHandler(functiontocall);
    myDispatcherTimer.Start();
}

public void functiontocall(object o, EventArgs sender)
{
    // do something here

    myDispatcherTimer.Stop();
}

private void ViewerTab_MouseEnter(object sender, MouseEventArgs e)
{
    myDispatcherTimer.Stop();
}