1 out of 1 rated this helpful - Rate this topic

SimpleOrientationSensor class

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

DualApiPartitionAttribute()
MarshalingBehaviorAttribute(Agile)
StaticAttribute(Windows.Devices.Sensors.ISimpleOrientationSensorStatics, NTDDI_WIN8)
ThreadingAttribute(Both)
VersionAttribute(NTDDI_WIN8)

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.

 

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

Windows Server 2012 [Windows Store apps, desktop apps]

Namespace

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

Metadata

Windows.winmd

See also

SimpleOrientation Sensor Quickstart
SimpleOrientation Sensor Sample

 

 

Build date: 2/25/2013

© 2013 Microsoft. All rights reserved.