using System;
using System.Security;
namespace Microsoft.Devices.Sensors
{
// Summary:
// Provides Windows?Phone applications access to the device’s accelerometer
// sensor.
public sealed class Accelerometer : IDisposable
{
// Summary:
// Creates a new instance of the Microsoft.Devices.Sensors.Accelerometer object.
[SecuritySafeCritical]
public Accelerometer();
// Summary:
// Gets the current state of the accelerometer. The value is a member of the
// Microsoft.Devices.Sensors.SensorState enumeration.
//
// Returns:
// Type Microsoft.Devices.Sensors.SensorState.
public SensorState State { get; }
// Summary:
// Occurs when new data arrives from the accelerometer.
public event EventHandler ReadingChanged;
// Summary:
// Releases the managed and unmanaged resources used by the Microsoft.Devices.Sensors.Accelerometer.
[SecuritySafeCritical]
public void Dispose();
//
// Summary:
// Starts data acquisition from the accelerometer.
[SecuritySafeCritical]
public void Start();
//
// Summary:
// Stops data acquisition from the accelerometer.
[SecuritySafeCritical]
public void Stop();
}
}
X轴表示左右方向的重力大小
Y轴表示上下方向的重力大小
Z轴表示屏幕正上方下面的的重力大小
实例
代码
MainPage.xaml
代码
MainPage.xaml.cs
using System;
using System.Windows;
using System.Windows.Controls;
using Microsoft.Devices.Sensors;
using Microsoft.Phone.Controls;
namespace SilverlightAccelerometer
{
public partial class MainPage : PhoneApplicationPage
{
public MainPage()
{
InitializeComponent();
Accelerometer acc = new Accelerometer();//初始化一个重力感应器的类
acc.ReadingChanged += OnAccelerometerReadingChanged;//触发重力感应的事件