I would like to determine the current orientation of the device in a WP7 app. I do not want to handle the OrientationChange event, because I need the current orientation when the page is opened.
I’ve been trying to do it with this piece of code I found in a forum:
((PhoneApplicationFrame)Application.Current.RootVisual).Orientation
However, this always returns with PortraitUp, even if I turn the device sideways. And by the way, I am trying to do this with the emulator, so it might be an emulator-bug.
Thanks
What I found out about this:
((PhoneApplicationFrame)Application.Current.RootVisual).Orientationdoes not have the correct orientation in PageLoaded.It does not give back the correct orientation in the first LayoutUpdated event either. However there is a second LayoutUpdated event, in which it gives the correct one.
And between the two LayoutUpdated events, if the last page was in another orientation, then there will be an OrientationChanged event as well.
So there was no other solution for me then waiting for the OrientationChanged event to happen (because the only page the user can come to this page from supports only Portrait mode).