如何确定的Windows Phone 7的方向是什么?
-
20-09-2019 - |
题
你怎么能告诉设备是否在垂直方向(纵向)定向或水平(横向)?
有没有简化这个还是你必须做出判断“手动”使用加速度计的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您的应用程序启动时让你知道的方向是什么。 Afther开始可以使用OrientationChanged事件。
在你的主要:
OrientationChanged += new EventHandler<OrientationChangedEventArgs>(MainPage_OrientationChanged);
void MainPage_OrientationChanged(object sender, OrientationChangedEventArgs e)
{
Console.WriteLine(e.Orientation.ToString());
}
不隶属于 StackOverflow