user3209792
user3209792

Reputation: 35

Stop action when button is released

In my WP8 app that controls Lego Mindstorms I have a Button with UIElement.Hold Event that triggers method runMotor() When I release the Button motor keeps on going but I would like it to stop. Method for stopping is stopMotor(), I've already tried to assign it to KeyUp Event but it doesn't work. Any solutions?

Upvotes: 2

Views: 131

Answers (1)

har07
har07

Reputation: 89285

You can try to call stopMotor() in ManupulationCompleted event. Note that ManipulationCompleted event will get invoked after any gesture manipulation including Tap, Double Tap, Hold, and other gesture. Take that into account. If application scenario is still simple, checking if motor already running before calling stopMotor in ManipulationCompleted event handler maybe enough :

private void MyButton_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
{
    if(isMotorRunning) stopMotor();
}

Upvotes: 2

Related Questions