WP7 程序在鎖屏後仍然能夠運作
我现在 写了一个SHAKE DETECTOR
当用家摇电话一下,画面的数字会自动加1
现在只能在 运行情况才能加1, 只要一锁屏, 用户怎摇 数字都不会增加
数字只会在 运行情况才能加1。
我的APP 源码在:
namespace ShakeTest
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
private ShakeDetector _shakeDecetor;
int co = 0;
public MainPage()
{
PhoneApplicationService.Current.ApplicationIdleDetectionMode = IdleDetectionMode.Disabled;
PhoneApplicationFrame rootFrame = App.Current.RootVisual as PhoneApplicationFrame;
if (rootFrame != null)
{
rootFrame.Obscured += new EventHandler<ObscuredEventArgs>(rootFrame_Obscured);
rootFrame.Unobscured += new EventHandler(rootFrame_Unobscured);
}
InitializeComponent();
_shakeDecetor = new ShakeDetector();
_shakeDecetor.ShakeEvent += new EventHandler<EventArgs>(_shakeDecetor_ShakeEvent);
_shakeDecetor.Start();
}
void _shakeDecetor_ShakeEvent(object sender, EventArgs e)
{
this.Dispatcher.BeginInvoke(() =>
{
count.Text = Convert.ToString(co);
co++;
});
}
void rootFrame_Unobscured(object sender, EventArgs e)
{
}
void rootFrame_Obscured(object sender, ObscuredEventArgs e)
{
}
}
}