您如何判断设备是垂直(纵向)还是水平(横向)?
是否有简化此操作的 API,或者您是否必须使用加速度计“手动”确定?
我自己刚刚看过 Windows 7 手机(通过 vs2010 快速手机版)。
它似乎在这背后的代码中
public MainPage()
{
InitializeComponent();
// seems to set the supported orientations that your program will support.
SupportedOrientations = SupportedPageOrientation.Portrait | SupportedPageOrientation.Landscape;
}
然后实际的形式有
private void PhoneApplicationPage_OrientationChanging(object sender, OrientationChangedEventArgs e)
{
var test = e.Orientation;
}
所以当方向改变时,e.Orientation 会告诉你它是什么方向。例如 LandscapeRight。
此外,您不必仅通过事件来跟踪它,您可以直接从 PhoneApplicationPage 实例中请求它:
private void Button_Click(object sender, RoutedEventArgs e)
{
MyCurrentOrientation.Text = this.Orientation.ToString();
}
您也可以在应用程序启动时通过 this.Orientation 询问它,以便您知道方向是什么。开始后,您可以使用 OrientationChanged 事件。
在你的主要:
OrientationChanged += new EventHandler<OrientationChangedEventArgs>(MainPage_OrientationChanged);
void MainPage_OrientationChanged(object sender, OrientationChangedEventArgs e)
{
Console.WriteLine(e.Orientation.ToString());
}