how to program hold event in silverlight/wp7

I got a little problem with button events. I programmed one button to decrease specific value by 1 (click), and I want to decrease it over time while holding button pressed. I'm using Silverlight, not XNA.

myTimer.Change(0, 100);
private void OnMyTimerDone(object state)
    {
        Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                if (rightButton.IsPressed)
                {
                    rightButton_Click(null, null);
                }
            });
    }

this code is correctly working at the beginning, but then I am unable to single tap as it is always calling hold event.

Answers


Try to use the RepeatButton silverlight control instead of using a normal Button

Here is an Example of how to use it:

XAML Code:

<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# Code:

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--;
}

Two suggestions, the first being to stop the timer (using a DispatcherTimer) if isPressed is false

void Button_MouseLeftButtonDown(object sender, EventArgs e)
{
    myTimer.Start();
}

void OnTimerTick(object s, EventArgs args)
{
    if(rightButton.IsPressed == false)
    {
        myTimer.Stop();
    }
    else
    {
        // decrease value
    }
}

the second being to stop the timer on the MouseLeftButtonUp event


Need Your Help

Differences between XMLHTTP and ServerXMLHTTP

vba excel-vba xmlhttprequest excel

I'm trying to write an Excel add-in that can get data from a web service into Excel.

paypal payments advanced missing token error

iframe paypal

I've been trying to get a transaction through on a PayPal payments advanced account for a few days now with no luck. I've done some searches for an answer, but none seem to fit. Here is what I am d...