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.

SimpleOrientationSensor class

Applies to Windows and Windows Phone

Represents a simple orientation sensor.

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

Syntax


var simpleOrientationSensor = Windows.Devices.Sensors.SimpleOrientationSensor;

Attributes

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

Members

The SimpleOrientationSensor class has these types of members:

Events

The SimpleOrientationSensor class has these events.

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

 

Methods

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

MethodDescription
GetCurrentOrientation Gets the default simple orientation sensor.
GetDefault Gets the default simple orientation sensor.

 

Properties

The SimpleOrientationSensor class has these properties.

PropertyAccess typeDescription

DeviceId

Read-onlyGets the device identifier.

 

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


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

SimpleOrientation Sensor Quickstart
SimpleOrientation Sensor Sample

 

 

Show:
© 2014 Microsoft