共用方式為


SimpleOrientationSensor.OrientationChanged 事件

定義

每次簡單的方向感應器報告新的感應器讀數時發生

// 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;
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) 

事件類型

範例

下列範例示範如何使用 C# 和 XAML 建置的 UWP 應用程式註冊其 OrientationChanged 事件處理常式。

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

下列範例示範如何使用 XAML 建置的 UWP 應用程式註冊 OrientationChanged 事件處理常式。

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

適用於