Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

LightSensor class

Applies to Windows and Windows Phone

Represents an ambient-light sensor.

This sensor returns the ambient-light reading as a LUX value.

Syntax


Public NotInheritable Class LightSensor

Attributes

[DualApiPartition()]
[MarshalingBehavior(Agile)]
[Threading(Both)]
[Version(0x06020000)]

Members

The LightSensor class has these types of members:

Events

The LightSensor class has these events.

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

 

Methods

The LightSensor class has these methods. With C#, Visual Basic, and C++, it also inherits methods from the Object class.

MethodDescription
GetCurrentReading Gets the current ambient-light sensor reading.
GetDefault Returns the default ambient-light sensor.

 

Properties

The LightSensor class has these properties.

PropertyAccess typeDescription

DeviceId

Read-onlyGets the device identifier.

MinimumReportInterval

Read-onlyGets the minimum report interval supported by the sensor.

ReportInterval

Read/writeGets or sets the current report interval for the ambient light sensor.

 

Remarks

The following example demonstrates how a Windows Store app built with XAML and C# uses the GetDefault method to establish a connection to a light sensor. If no integrated light sensor is found, the method will return a null value.


_sensor = LightSensor.GetDefault();


The following example demonstrates how a Windows Store app built with XAML registers a 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;
    }
    else
    {
        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);
    });
}


Requirements

Minimum supported client

Windows 8 [Windows Store apps, desktop apps]

Minimum supported server

None supported [Windows Store apps, desktop apps]

Minimum supported phone

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

Namespace

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

Metadata

Windows.winmd

See also

LightSensor Quickstart
LightSensor Sample

 

 

Show:
© 2014 Microsoft