LightSensor class
Represents an ambient-light sensor.
This sensor returns the ambient-light reading as a LUX value.
Syntax
public ref class LightSensor sealed : Object
Attributes
- DualApiPartitionAttribute()
- MarshalingBehaviorAttribute(Agile)
- StaticAttribute(Windows.Devices.Sensors.ILightSensorStatics, NTDDI_WIN8)
- ThreadingAttribute(Both)
- VersionAttribute(NTDDI_WIN8)
Members
The LightSensor class has these types of members:
Events
The LightSensor class has these events.
| Event | Description |
|---|---|
| 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.
| Method | Description |
|---|---|
| GetCurrentReading | Gets the current ambient-light sensor reading. |
| GetDefault | Returns the default ambient-light sensor. |
Properties
The LightSensor class has these properties.
| Property | Access type | Description |
|---|---|---|
| Read-only | Gets the minimum report interval supported by the sensor. | |
| Read/write | Gets 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 | Windows Server 2012 [Windows Store apps, desktop apps] |
|
Namespace |
|
|
Metadata |
|
See also
Build date: 2/25/2013
