我在按钮事件方面遇到了一些问题。我对一个按钮进行了编程,将特定值减少 1(单击),并且我想在按住按钮的同时随着时间的推移减少该值。我使用的是 Silverlight,而不是 XNA。
myTimer.Change(0, 100);
private void OnMyTimerDone(object state)
{
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
if (rightButton.IsPressed)
{
rightButton_Click(null, null);
}
});
}
这段代码一开始工作正常,但后来我无法单击,因为它总是调用保持事件。
最佳答案
尝试使用RepeatButton silverlight控件而不是使用普通的Button
以下是如何使用它的示例:
XAML 代码:
<RepeatButton x:Name="rbtnDecrease" Content="Decrease" Delay="200" Interval="100" Click="rbtnDecrease_Click" />
Delay: The amount of time, in milliseconds, the RepeatButton waits while it is pressed before it starts repeating.
Interval: The amount of time, in milliseconds, between repeats once repeating starts.
C# 代码:
private int tempCount = 100; // A temp Variable used as an Example
private void rbtnDecrease_Click(object sender, RoutedEventArgs e){
// Add your Button Click/Repeat Code Here...
// Example of Decreasing the value of a Variable
tempCount--;
}
关于silverlight - 如何在 silverlight/wp7 中编程保持事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11568025/