问题
I can get the phone to react to a shake, but what is the best way to tell that it has stopped shaking?
回答1:
This example worked for me.
At the very bottom of the page you'll see:
if (!_shaking && CheckForShake(_lastReading, reading, ShakeThreshold) && _shakeCount >= 1)
{
//We are shaking
_shaking = true;
_shakeCount = 0;
OnShakeDetected();
}
else if (CheckForShake(_lastReading, reading, ShakeThreshold))
{
_shakeCount++;
}
else if (!CheckForShake(_lastReading, reading, 0.2))
{
_shakeCount = 0;
_shaking = false;
}
回答2:
Do like #Daniel Pereira said, but in the void ShakeDetected(object sender, EventArgs e) use a Dispatcher.BeginInvoke(() => youMethod()); and do what you pretend to do in youMethod(). I know this post is a little old but now other people can know how it resolve
来源:https://stackoverflow.com/questions/7357171/how-to-detect-that-the-phone-wp7-has-stopped-shaking