Inclinometer.ReadingChanged 事件

定义

每次测斜仪报告新的传感器读数时发生。

// Register
event_token ReadingChanged(TypedEventHandler<Inclinometer, InclinometerReadingChangedEventArgs const&> const& handler) const;

// Revoke with event_token
void ReadingChanged(event_token const* cookie) const;

// Revoke with event_revoker
Inclinometer::ReadingChanged_revoker ReadingChanged(auto_revoke_t, TypedEventHandler<Inclinometer, InclinometerReadingChangedEventArgs const&> const& handler) const;
public event TypedEventHandler<Inclinometer,InclinometerReadingChangedEventArgs> ReadingChanged;
function onReadingChanged(eventArgs) { /* Your code */ }
inclinometer.addEventListener("readingchanged", onReadingChanged);
inclinometer.removeEventListener("readingchanged", onReadingChanged);
- or -
inclinometer.onreadingchanged = onReadingChanged;
Public Custom Event ReadingChanged As TypedEventHandler(Of Inclinometer, InclinometerReadingChangedEventArgs) 

事件类型

示例

以下示例演示了使用 C# 和 XAML 生成的 UWP 应用如何注册其 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);
    });
}

注解

应用程序可以通过设置 ReportInterval 属性来设置此事件的频率。

适用于