Oritentationchanged event for Windows Phone development (12)

Source: Internet
Author: User

When the direction of our mobile phone changes, some events are actually triggered. Both phoneapplicationframe and phoneapplicationpage contain the oritentationchanged event. Phoneapplicationpage also adds a convenient equivalent method onoritentationchanged, which is protected and Rewritable. The following example demonstrates how to rewrite the onoritentationchanged method in the project and display the direction of the current mobile phone in a textblock.

XAML code:

<Grid x:Name="LayoutRoot" Background="Transparent">
<TextBlock Name="txtblk" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>

C # code:

Public partial class mainpage: phoneapplicationpage
{
// Constructor
Public mainpage ()
{
Initializecomponent ();

Txtblk. Text = This. Orientation. tostring (); // gets the value of the orientation attribute of the current page.
}

Protected override void onorientationchanged (orientationchangedeventargs e) // rewrite the virtual method onorientationchanged of the base class phoneapplicationpage
{
Txtblk. Text = E. Orientation. tostring (); // get the new value of the attribute orientation after the direction is changed.
Base. onorientationchanged (E); // call the onorientationchanged method of the base class
}
}

Effect


Vertical direction horizontal direction

The preceding example shows that you can modify the application direction not only through the supportedorientations attribute in the XAML code, but also through the C # code modification page oritentation. In addition, when the mobile phone direction changes, the program will trigger the orientationchanged event accordingly. We can use this event to handle some things.

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.