ReadingChanged | readingchanged event

LightSensor.ReadingChanged | readingchanged event

[ Updated for UWP apps on Windows 10. For Windows 8.x articles, see the archive ]

Occurs each time the ambient-light sensor reports a new sensor reading.


function onReadingChanged(eventArgs) { /* Your code */ }
// addEventListener syntax
lightSensor.addEventListener("readingchanged", onReadingChanged);
lightSensor.removeEventListener("readingchanged", onReadingChanged);
- or -

lightSensor.onreadingchanged = onReadingChanged;

Event information

Delegate TypedEventHandler<LightSensor, LightSensorReadingChangedEventArgs>


An application may register this event handler to obtain sensor readings. The application must establish a desired ReportInterval. This informs the sensor driver that resources should be allocated to satisfy the requirements of the application.

Applications can set the frequency of this event by setting the ReportInterval property.

The following example demonstrates how a Windows Store app built with C# and XAML registers its ReadingChanged event handler.

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

        Window.Current.VisibilityChanged += new WindowVisibilityChangedEventHandler(VisibilityChanged);
        _sensor.ReadingChanged += new TypedEventHandler<LightSensor, LightSensorReadingChangedEventArgs>(ReadingChanged);

        ScenarioEnableButton.IsEnabled = false;
        ScenarioDisableButton.IsEnabled = true;
        rootPage.NotifyUser("No light sensor found", NotifyType.StatusMessage);

The following example shows the ReadingChanged event handler.

async private void ReadingChanged(object sender, LightSensorReadingChangedEventArgs e)
    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
        LightSensorReading reading = e.Reading;
        ScenarioOutput_LUX.Text = String.Format("{0,5:0.00}", reading.IlluminanceInLux);

The following example demonstrates how a Windows Store appbulit with JavaScript registers its ReadingChanged event handler.

function enableReadingChangedScenario() {
    if (lightSensor) {
        // Set the reportInterval to enable the sensor events
        lightSensor.reportInterval = reportInterval;

        document.addEventListener("msvisibilitychange", msVisibilityChangeHandler, false);
        lightSensor.addEventListener("readingchanged", onDataChanged);
        document.getElementById("scenario1Open").disabled = true;
        document.getElementById("scenario1Revoke").disabled = false;
    } else {
        WinJS.log && WinJS.log("No light sensor found", "sample", "error");

The following example shows the ReadingChanged event handler.

function onDataChanged(e) {
    var reading = e.reading;

    document.getElementById("eventOutputIlluminance").innerHTML = e.reading.illuminanceInLux.toFixed(2);

Requirements (Windows 10 device family)

Device family


API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0


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



Requirements (Windows 8.x and Windows Phone 8.x)

Minimum supported client

Windows 8

Minimum supported server

None supported

Minimum supported phone

Windows Phone 8.1 [Windows Phone Silverlight 8.1 and Windows Runtime apps]


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



See also




© 2016 Microsoft