SimpleOrientationSensor.OrientationChanged Event
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Occurs each time the simple orientation sensor reports a new sensor reading
// Register
event_token OrientationChanged(TypedEventHandler<SimpleOrientationSensor, SimpleOrientationSensorOrientationChangedEventArgs const&> const& handler) const;
// Revoke with event_token
void OrientationChanged(event_token const* cookie) const;
// Revoke with event_revoker
SimpleOrientationSensor::OrientationChanged_revoker OrientationChanged(auto_revoke_t, TypedEventHandler<SimpleOrientationSensor, SimpleOrientationSensorOrientationChangedEventArgs const&> const& handler) const;
C#
public event TypedEventHandler<SimpleOrientationSensor,SimpleOrientationSensorOrientationChangedEventArgs> OrientationChanged;
function onOrientationChanged(eventArgs) { /* Your code */ }
simpleOrientationSensor.addEventListener("orientationchanged", onOrientationChanged);
simpleOrientationSensor.removeEventListener("orientationchanged", onOrientationChanged);
- or -
simpleOrientationSensor.onorientationchanged = onOrientationChanged;
Public Custom Event OrientationChanged As TypedEventHandler(Of SimpleOrientationSensor, SimpleOrientationSensorOrientationChangedEventArgs)
The following example demonstrates how a UWP app built with C# and XAML registers its OrientationChanged event handler.
C#
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 UWP app built with XAML registers an OrientationChanged event handler.
C#
async private void OrientationChanged(object sender, SimpleOrientationSensorOrientationChangedEventArgs e)
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
DisplayOrientation(ScenarioOutput_Orientation, e.Orientation);
});
}
C#
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;
}
}
Product | Versions |
---|---|
WinRT | Build 10240, Build 10586, Build 14383, Build 15063, Build 16299, Build 17134, Build 17763, Build 18362, Build 19041, Build 20348, Build 22000, Build 22621, Build 26100 |