开发者

C# WPF Perform action while button down

How can I detect that the button in my开发者_开发技巧 application is still clicked (down)? and how to know when it is released?


Are you looking for RepeatButton? It's one of the built-in WPF button controls, and it raises its Click event repeatedly if you press and hold the button. It's used internally to implement things like the "up-arrow" and "down-arrow" buttons on a scrollbar.


Try using the MouseDown and MouseUp events

Example:

XAML:

<Button x:Name="Button1" MouseDown="OnMouseDown" Content="Button1" />

Code behind:

private void OnMouseDown(object sender, MouseButtonEventArgs e)
{
    //do something
}

Same goes for MouseUp


You need to handle the MouseDown and MouseUp events.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜