在 MainPage.xaml 文件的 XAML 代码中,将以下代码添加到页面顶部的 phone:PhoneApplicationPage 下。
OrientationChanged="PhoneApplicationPage_OrientationChanged"
转到 MainPage.xaml.cs 并找到事件处理程序。下面的代码根据方向更改来切换按键列表的位置。
private void PhoneApplicationPage_OrientationChanged(object sender, OrientationChangedEventArgs e) { // Switch the placement of the buttons based on an orientation change. if ((e.Orientation & PageOrientation.Portrait) == (PageOrientation.Portrait)) { Grid.SetRow(buttonList, 1); Grid.SetColumn(buttonList, 0); } // If not in the portrait mode, move buttonList content to a visible row and column. else { Grid.SetRow(buttonList, 0); Grid.SetColumn(buttonList, 1); } }