silverlight - 如何在 silverlight/wp7 中编程保持事件

标签 silverlight windows-phone-7

我在按钮事件方面遇到了一些问题。我对一个按钮进行了编程,将特定值减少 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/

相关文章:

silverlight - 如何根据当前主题更改应用程序栏中的图标?

linq - Silverlight 中不存在 List<T>.RemoveAll 吗?

silverlight - 使用转义字符串格式进行绑定(bind)会破坏 VS IDE 和智能感知

c++ - 我们可以使用c来开发Windows Phone 7.5应用程序吗?

windows-phone-7 - System.Windows.Navigation.NavigationService.Navigate 抛出无效操作异常

silverlight - 使用 MVVM 定期更新 silverlight View

silverlight - 如何在我的 WP7 应用程序中获取当前页面

c# - Restsharp反序列化服务器端错误

windows-phone-7 - SkyDrive 的编程访问

silverlight - 使用 WCF 将 Linq-to-Sql 对象发送到服务器时出错