共用方式為


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 屬性來設定此事件的頻率。

適用於