简体   繁体   中英

WPF Initial Delay on RepeatButton

当ClickMode为'Hover'时,如何在RepeatButton上设置初始延迟(在触发首次单击事件之前)?

Looking at the code in Reflector, ButtonBase calls OnClick from OnMouseEnter if ClickMode is set to Hover, so there is nothing you can set that will prevent that initial click. You could subclass RepeatButton and try to completely suppress the OnClick call if it's made during OnMouseEnter:

public class DelayRepeatButton
    : RepeatButton
{
    private bool duringMouseEnter = false;

    protected override void OnMouseEnter(MouseEventArgs e)
    {
        try
        {
            duringMouseEnter = true;
            base.OnMouseEnter(e);
        }
        finally
        {
            duringMouseEnter = false;
        }
    }

    protected override void OnClick()
    {
        if (!duringMouseEnter)
        {
            base.OnClick();
        }
    }
}

If you want that to work for other ClickMode values, you could do something similar for OnKeyDown, OnKeyUp, OnLeftMouseButtonDown, and OnLeftMouseButtonUp.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM