开发者

WPF Initial Delay on RepeatButton

How can I set an initial delay on a RepeatButton(before first click ev开发者_StackOverflow中文版ent is fired) when ClickMode is 'Hover' ?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜