SimpleOrientationSensor SimpleOrientationSensor SimpleOrientationSensor SimpleOrientationSensor 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 : sealed class SimpleOrientationSensor
struct winrt::Windows::Devices::Sensors::SimpleOrientationSensor
public sealed class SimpleOrientationSensor
Public NotInheritable Class SimpleOrientationSensor
// This class does not provide a public constructor.
Attributes

Windows 10 requirements

Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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;
    }
}

Properties

DeviceId DeviceId DeviceId DeviceId DeviceId

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

ReadingTransform ReadingTransform ReadingTransform ReadingTransform 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) FromIdAsync(String) FromIdAsync(String) FromIdAsync(String) FromIdAsync(String)

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

GetCurrentOrientation() GetCurrentOrientation() GetCurrentOrientation() GetCurrentOrientation() GetCurrentOrientation()

Gets the default simple orientation sensor.

GetDefault() GetDefault() GetDefault() GetDefault() GetDefault()

Gets the default simple orientation sensor.

GetDeviceSelector() GetDeviceSelector() GetDeviceSelector() GetDeviceSelector() GetDeviceSelector()

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

Events

OrientationChanged OrientationChanged OrientationChanged OrientationChanged OrientationChanged

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

See also