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.
精彩评论