SimpleOrientationSensor Class

Definition

Represents a simple orientation sensor.

For an example implementation, see the simple orientation sensor sample.

This sensor detects the current quadrant orientation of the specified device as well as its face-up or face-down status.

public ref class SimpleOrientationSensor sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class SimpleOrientationSensor final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class SimpleOrientationSensor
Public NotInheritable Class SimpleOrientationSensor
Inheritance
Object Platform::Object IInspectable SimpleOrientationSensor
Attributes

Windows requirements

Device family
Windows 10 (introduced in 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v1.0)

Remarks

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

_sensor = SimpleOrientationSensor.GetDefault();

The following example demonstrates how a UWP app built with XAML registers a OrientationChanged event handler.

private void ScenarioEnable(object sender, RoutedEventArgs e)
{
    if (_sensor != null)
    {
        Window.Current.VisibilityChanged += new WindowVisibilityChangedEventHandler(VisibilityChanged);
        _sensor.OrientationChanged += new TypedEventHandler<SimpleOrientationSensor, SimpleOrientationSensorOrientationChangedEventArgs>(OrientationChanged);

        ScenarioEnableButton.IsEnabled = false;
        ScenarioDisableButton.IsEnabled = true;

        // Display the current orientation once while waiting for the next orientation change
        DisplayOrientation(ScenarioOutput_Orientation, _sensor.GetCurrentOrientation());
    }
    else
    {
        rootPage.NotifyUser("No simple orientation sensor found", NotifyType.StatusMessage);
    }
}

The following example contains the XAML code for the event handler which writes the orientation readings to the application's form.

async private void OrientationChanged(object sender, SimpleOrientationSensorOrientationChangedEventArgs e)
{
    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
    {
        DisplayOrientation(ScenarioOutput_Orientation, e.Orientation);
    });
}
private void DisplayOrientation(TextBlock tb, SimpleOrientation orientation)
{
    switch (orientation)
    {
        case SimpleOrientation.NotRotated:
            tb.Text = "Not Rotated";
            break;
        case SimpleOrientation.Rotated90DegreesCounterclockwise:
            tb.Text = "Rotated 90 Degrees Counterclockwise";
            break;
        case SimpleOrientation.Rotated180DegreesCounterclockwise:
            tb.Text = "Rotated 180 Degrees Counterclockwise";
            break;
        case SimpleOrientation.Rotated270DegreesCounterclockwise:
            tb.Text = "Rotated 270 Degrees Counterclockwise";
            break;
        case SimpleOrientation.Faceup:
            tb.Text = "Faceup";
            break;
        case SimpleOrientation.Facedown:
            tb.Text = "Facedown";
            break;
        default:
            tb.Text = "Unknown orientation";
            break;
    }
}

Version history

Windows version SDK version Value added
1809 17763 FromIdAsync
1809 17763 GetDeviceSelector

Properties

DeviceId

Gets the device identifier used in the SimpleOrientationSensor.FromIdAsync method.

ReadingTransform

Gets or sets the transformation that needs to be applied to sensor data. Transformations to be applied are tied to the display orientation with which to align the sensor data.

Methods

FromIdAsync(String)

Asynchronously retrieves a SimpleOrientationSensor object based on the specified device identifier.

GetCurrentOrientation()

Gets the default simple orientation sensor.

GetDefault()

Gets the default simple orientation sensor.

GetDeviceSelector()

Retrieves an Advanced Query Syntax (AQS) string used to enumerate the available SimpleOrientationSensor devices.

Events

OrientationChanged

Occurs each time the simple orientation sensor reports a new sensor reading

Applies to

See also