Windows Phone 7의 Orientation을 PortraitOrLandscape로 설정했다면 현재의 Orientation을 얻어오거나 Orientation이 변경되는 시점을 알아야할 때가 있습니다.
현재의 Orientation을 얻어오려면 PhoneApplicationPage.Orientation Property를 사용하면 되고, Orientation이 변경되는 시점을 알고 싶으면 PhoneApplicationPage.OrientationChanged Event를 등록해서 사용하면 됩니다.
아래는 샘플코드이고 둘다 PageOrientation enum값을 사용합니다.
public partial class MainPage : PhoneApplicationPage { public MainPage() { InitializeComponent(); //Add EventHandler this.OrientationChanged += new EventHandler(MainPage_OrientationChanged); } void MainPage_OrientationChanged(object sender, OrientationChangedEventArgs e) { PageOrientation orientation = e.Orientation; //Check current orientation if ((orientation & PageOrientation.Portrait) == (PageOrientation.Portrait)) { // Portrait } else { // Landscape } } PageOrientation GetCurrentOrientation() { return this.Orientation; } }
Orientation에 대한 자세한 정보는 아래 MSDN을 참고하세요~