質問
どのようにデバイスを水平方向(ポートレート)または(風景)、垂直に配向されているかどうかを伝えることができますか?
これを単純化したり、加速度計を使用して「手で」決意を作るために持っているAPIはありますか?
解決
私は自分自身がちょうど窓を見てきました(VS2010 Expressの電話版を介して)7電話ます。
この背後にあるコードを持っているようです。
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