Accelerometer 重力感应类
引用命名空间using Microsoft.Devices.Sensors;using Microsoft.Xna.Framework;private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e) { if (!Accelerometer.IsSupported) { MessageBox.Show("很抱歉,您的设备不支持加速计传感器"); return; } else { Acc = new Accelerometer(); Acc.CurrentValueChanged += new EventHandler<SensorReadingEventArgs<AccelerometerReading>>(Acc_CurrentValueChanged); //Acc.ReadingChanged 事件已经过时 Acc.TimeBetweenUpdates = TimeSpan.FromMilliseconds(100); //100毫秒监控一次 Acc.Start(); //开始监控 } } void Acc_CurrentValueChanged(object sender, SensorReadingEventArgs<AccelerometerReading> e) { System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() => { this.textBlock1.Text = "X:"+e.SensorReading.Acceleration.X.ToString(); this.textBlock2.Text = "Y:" + e.SensorReading.Acceleration.Y.ToString(); this.textBlock3.Text = "Z:" + e.SensorReading.Acceleration.Z.ToString(); }); //throw new NotImplementedException(); }
TAG: