SimpleOrientationSensor 类  
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
public ref class SimpleOrientationSensor sealed
	/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class SimpleOrientationSensor final
	[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class SimpleOrientationSensor
	Public NotInheritable Class SimpleOrientationSensor
		- 继承
 
- 属性
 
Windows 要求
| 设备系列 | 
					 
							Windows 10 (在 10.0.10240.0 中引入) 
				 | 
			
| API contract | 
					 
							Windows.Foundation.UniversalApiContract (在 v1.0 中引入) 
				 | 
			
注解
以下示例演示了使用 XAML 和 C# 生成的 UWP 应用如何使用 GetDefault 方法建立与简单方向传感器的连接。 如果未找到简单的方向传感器,该方法将返回 null 值。
_sensor = SimpleOrientationSensor.GetDefault();
以下示例演示使用 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 代码,该事件处理程序将方向读数写入应用程序的窗体。
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;
    }
}
版本历史记录
| Windows 版本 | SDK 版本 | 已添加值 | 
|---|---|---|
| 1809 | 17763 | FromIdAsync | 
| 1809 | 17763 | GetDeviceSelector | 
属性
| DeviceId | 
		 获取 SimpleOrientationSensor.FromIdAsync 方法中使用的设备标识符。  | 
        	
| ReadingTransform | 
		 获取或设置需要应用于传感器数据的转换。 要应用的转换与用于对齐传感器数据的显示方向相关联。  | 
        	
方法
| FromIdAsync(String) | 
		 基于指定的设备标识符异步检索 SimpleOrientationSensor 对象。  | 
        	
| GetCurrentOrientation() | 
		 获取默认的简单方向传感器。  | 
        	
| GetDefault() | 
		 获取默认的简单方向传感器。  | 
        	
| GetDeviceSelector() | 
		 检索用于枚举可用 SimpleOrientationSensor 设备的 AQS) 字符串 (高级查询语法。  | 
        	
事件
| OrientationChanged | 
		 每次简单方向传感器报告新的传感器读数时发生  |