此主题尚未评级 - 评价此主题

Inclinometer Class

表示磁倾仪传感器。

此传感器分别返回对应于 x、 y 和 z 轴旋转角度的斜度、旋转度和偏转度。

语法

Public NotInheritable Class Inclinometer  
    Inherits Object

特性

DualApiPartitionAttribute()
MarshalingBehaviorAttribute(Agile)
StaticAttribute(Windows.Devices.Sensors.IInclinometerStatics, NTDDI_WIN8)
ThreadingAttribute(Both)
VersionAttribute(NTDDI_WIN8)

成员

Inclinometer类 具有以下类型的成员:

事件

Inclinometer类 具有以下事件。

事件描述
ReadingChanged Occurs each time the inclinometer reports a new sensor reading.

 

方法

The Inclinometer 类 具有以下方法。 使用 C#、Visual Basic 和 C++,它还可以继承以下内容中的方法 Object 类.

方法描述
GetCurrentReading Gets the current inclinometer reading.
GetDefault Returns the default inclinometer.

 

属性

Inclinometer类 具有以下属性。

属性访问类型描述

MinimumReportInterval

只读Gets the minimum report interval supported by the inclinometer.

ReportInterval

读取/写入Gets or sets the current report interval for the inclinometer.

 

备注

下面的示例演示使用 XAML 和 C# 生成的 Windows 应用商店应用如何使用 GetDefault 方法建立到磁倾仪的连接。如果未找到集成磁倾仪,则方法返回一个 null 值。


_inclinometer = Inclinometer.GetDefault();


下面的示例演示使用 XAML 生成的 Windows 应用商店应用如何注册 ReadingChanged 事件处理程序。


private void ScenarioEnable(object sender, RoutedEventArgs e)
{
    if (_inclinometer != null)
    {
        // Establish the report interval
        _inclinometer.ReportInterval = _desiredReportInterval;

        Window.Current.VisibilityChanged += new WindowVisibilityChangedEventHandler(VisibilityChanged);
        _inclinometer.ReadingChanged += new TypedEventHandler<Inclinometer, InclinometerReadingChangedEventArgs>(ReadingChanged);

        ScenarioEnableButton.IsEnabled = false;
        ScenarioDisableButton.IsEnabled = true;
    }
    else
    {
        rootPage.NotifyUser("No inclinometer found", NotifyType.StatusMessage);
    }
}


下面的示例演示 ReadingChanged 事件处理程序。


async private void ReadingChanged(object sender, InclinometerReadingChangedEventArgs e)
{
    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
    {
        InclinometerReading reading = e.Reading;
        ScenarioOutput_X.Text = String.Format("{0,5:0.00}", reading.PitchDegrees);
        ScenarioOutput_Y.Text = String.Format("{0,5:0.00}", reading.RollDegrees);
        ScenarioOutput_Z.Text = String.Format("{0,5:0.00}", reading.YawDegrees);
    });
}


要求

最低受支持的客户端

Windows 8 [Windows 应用商店应用, 桌面应用]

最低受支持的服务器

Windows Server 2012 [Windows 应用商店应用, 桌面应用]

最低受支持的电话

Windows Phone 8

命名空间

Windows.Devices.Sensors
Windows::Devices::Sensors [C++]

元数据

Windows.winmd

另请参阅

磁倾仪快速入门
磁倾仪示例

 

 

本文是否对您有所帮助?
(1500 个剩余字符)
© 2013 Microsoft. 版权所有。