Quickly build Windows 8 style Apps 10-device orientation

Source: Internet
Author: User

Original: Quickly build Windows 8 style Apps 10-device orientation

This post focuses on the direction of commonly used devices that support Windows 8 operating systems, how to obtain the current device orientation, and the DisplayProperties class.

Common support for Windows 8 direction of operating system devices

What does Windows 8 do to monitor device orientation in the devices we use most often? The answer is the direction sensor , so for the different directions of the device, which direction sensor corresponds to which directional values? As the following table:

We can tell from the table that:

1) When the device direction is horizontally upward (Portraitup) , the corresponding sensor value is notrotated(no rotation);

We can identify different orientations by comparing the location of the Windows buttons in the device, as shown in:

2) When the device orientation is vertical to the left (Landscape) , the corresponding sensor value is rotated90degreescounterclockwise We can identify different orientations by comparing the location of the Windows button in the device, as shown in:

3) When the device direction is horizontal downward (Portraitdown) , the corresponding sensor value is rotated180degreescounterclockwise (Rotate , we can identify different orientations by comparing the location of the Windows button in the device, as shown in:

4) When the device direction is in vertical direction (Landscaperight) , the corresponding sensor value is rotated270degreescounterclockwise We can identify different orientations by comparing the location of the Windows buttons in the device, as shown in:

5) When the device direction is facing upward (face up) , the corresponding sensor value is faceup;

6) When the device direction is facing downward (face down) , the corresponding sensor value is facedown;

How to get the current device orientation value

How do we get this device orientation value in the code?

First step: Initialize the Simpleorientationsensor sensor object.

Step Two: Register the Sensor orientationchanged event.

Step three: Pass E in the Orientationchanged event method. The Orientation property gets the direction value.

The specific code can be as follows:

The Displayorientation method in the code is as follows:

If we use xaml+c# to write a game class application, we can control the different state of the game characters by monitoring the change of the value of the device.

displayproperties class

Microsoft has provided a very important class for developers:displayproperties. The code in which we obtain the device orientation value is implemented by this class.

So what are the important events and attributes that the DisplayProperties class contains?

1) orientationchanged Event: The event is triggered when the direction is changed;

2) Currentorientation Property: This property is read-only and gets the orientation of the current device;

3) Nativeorientation Property: This property is read-only, gets the direction supported by the device default, contains two values: Landscape and Portrait;

4) Autorotationpreferences Property: This property is a read-write property that allows you to read or set the preferred orientation of our app. Note: The settings for this property cannot be supported in the emulator.

Quickly build Windows 8 style Apps 10-device orientation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.