A smartphone or a tablet can be placed in various orientations, such as with the screen faced down, up, or rotated. Fortunately, it is possible to easily get to know which orientation is currently being used and to adjust the design of the page if necessary. In this recipe, you will learn how to use the SimpleOrientationSensor
class to get such information.
As an example, you will create a simple page with information about the current orientation. Of course, such content will be updated automatically as soon as the reading has changed.
To prepare an example presenting an information about the current orientation of the device, perform the following steps:
Add to the page the header (with the icon and the Device orientation text) and the label where the current orientation state is presented by modifying the content of the
MainPage.xaml
file as follows...