使用加速计时出现未经授权的访问异常
本文关键字:授权 访问 异常 加速 | 更新日期: 2023-09-27 18:29:30
每次用户摇动windows phone设备时,我都会尝试在页面之间导航,但每次更改轴时,都会显示未经授权的访问异常
public Welcome_2()
{
InitializeComponent();
Accelerometer acc = new Accelerometer();
acc.TimeBetweenUpdates = TimeSpan.FromMilliseconds(5);
acc.CurrentValueChanged += new EventHandler<SensorReadingEventArgs<AccelerometerReading>>(accEventHandler);
acc.Start();
}
private void accEventHandler(object sender, SensorReadingEventArgs<AccelerometerReading> e)
{
Vector3 accelReading = new Vector3();
accelReading.X = (float)e.SensorReading.Acceleration.X;
accelReading.Y = (float)e.SensorReading.Acceleration.Y;
accelReading.Z = (float)e.SensorReading.Acceleration.Z;
if (accelReading.X > 0 || accelReading.X < 0)
{
NavigationService.Navigate(new Uri("/Get_Insert.xaml", UriKind.Relative));
}
}
若要使用传感器(加速计),请将Microsoft.Devices.sensors和Microsoft.Xna.Framework引用添加到项目中。还要确保在项目的Properties文件夹下的应用程序清单文件的功能中检查ID_CAP_SENSORS功能