Occurs each time the simple orientation sensor reports a new sensor reading
Syntax
function onOrientationChanged(eventArgs) { /* Your code */ } // addEventListener syntax simpleOrientationSensor.addEventListener("orientationchanged", onOrientationChanged); simpleOrientationSensor.removeEventListener("orientationchanged", onOrientationChanged); - or - simpleOrientationSensor.onorientationchanged = onOrientationChanged;
Event information
| Delegate | TypedEventHandler<SimpleOrientationSensor, SimpleOrientationSensorOrientationChangedEventArgs> |
|---|
Remarks
The following example demonstrates how a Windows Store app built with C# and XAML registers its 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 demonstrates how a Windows Store app built with XAML registers an OrientationChanged event handler.
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; } }
The following example demonstrates how a Windows Store appbuilt with JavaScript registers its OrientationChanged event handler.
function enableReadingChangedScenario() { if (sensor) { document.addEventListener("msvisibilitychange", msVisibilityChangeHandler, false); sensor.addEventListener("orientationchanged", onDataChanged); document.getElementById("scenario1Open").disabled = true; document.getElementById("scenario1Revoke").disabled = false; } else { WinJS.log && WinJS.log("No simple orientation sensor found", "sample", "error"); } }
The following example shows the OrientationChanged event handler.
function onDataChanged(e) { switch (e.orientation) { case Windows.Devices.Sensors.SimpleOrientation.notRotated: document.getElementById("eventOutputOrientation").innerHTML = "Not Rotated"; break; case Windows.Devices.Sensors.SimpleOrientation.rotated90DegreesCounterclockwise: document.getElementById("eventOutputOrientation").innerHTML = "Rotated 90"; break; case Windows.Devices.Sensors.SimpleOrientation.rotated180DegreesCounterclockwise: document.getElementById("eventOutputOrientation").innerHTML = "Rotated 180"; break; case Windows.Devices.Sensors.SimpleOrientation.rotated270DegreesCounterclockwise: document.getElementById("eventOutputOrientation").innerHTML = "Rotated 270"; break; case Windows.Devices.Sensors.SimpleOrientation.faceup: document.getElementById("eventOutputOrientation").innerHTML = "Face Up"; break; case Windows.Devices.Sensors.SimpleOrientation.facedown: document.getElementById("eventOutputOrientation").innerHTML = "Face Down"; break; default: document.getElementById("eventOutputOrientation").innerHTML = "Undefined orientation " + e.orientation; break; } }
Requirements
|
Minimum supported client | Windows 8 |
|---|---|
|
Minimum supported server | Windows Server 2012 |
|
Namespace |
|
|
Metadata |
|
See also
Build date: 2/25/2013