开发者

C# WPF Perform action while button down

开发者 https://www.devze.com 2023-01-06 14:14 出处:网络
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 co

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

精彩评论

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

关注公众号