WPF跟踪buttondown事件的最佳方法 [英] WPF best way to track buttondown event
本文介绍了WPF跟踪buttondown事件的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要每500毫秒增加一次我的属性值如果按钮被按下/按下.
这是示例代码片段
XAML
Hi I need to increase my property value every 500ms IF button is pressed/down.
Here is example code snippet
XAML
<Button Height="50" Width="100" Content="PressMe" MouseDown="Button_MouseDown"></Button>
private void Button_MouseDown(object sender, MouseButtonEventArgs e)
{
Value = Value + 1;
System.Threading.Thread.Sleep(500);
}
问题是我的事件永远不会触发.如果我在xaml中创建mouseClick事件,则会触发它,但不符合我的需求.
希望你有我的主意:)
干杯!
The problem is that my event never fires up. If I create mouseClick event in xaml it fires up, but doest fit my needs.
Hope you got my idea :)
Cheers!
推荐答案
您可能需要在ButtonDown
事件上创建一个线程,并在ButtonUp
事件上中止该线程.
线程将坐/旋转直到中止,然后每1/2秒(或您指定的间隔)增加目标值.
如果是我,我会使用BackgroundWorker
对象作为我的线程处理,因为它很容易从对象外部取消.
You probably need to create a thread on theButtonDown
event, and abort that thread on theButtonUp
event.
The thread will sit/spin until aborted, and every 1/2 second (or the interval you specify), the target value is increased.
If it were me, I''d use aBackgroundWorker
object as my thread processing because it''s easily cancellable from outside the object.
这篇关于WPF跟踪buttondown事件的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文