How to Get the Height and Width of the Page on changing orientation in Windows Phone?

Published on September 25, 2013 by abundantcode

Filed under Windows Phone

Last modified September 25, 2013

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 0 (0 votes)

This article have been viewed 3979 times

Sometimes, you might want to determine the Height and Width of the Page in a Windows Phone app in order to adjust the screen and the UI elements in the Orientation changed event.

The actual size of the page will not be modified until the OnOrientationChanged event is called and hence it is necessary to use the Dispatcher which lets you get the current height and width of the page in Windows Phone.

How to Get the Height and Width of the Page on changing orientation in Windows Phone using C#?

Below is a sample code snippet demonstrating how to retrieve the Height and Width of the Page on changing orientation in Windows Phone using C#. Make sure you set the SupportedOrientations=”PortraitOrLandscape” for the screen to support both the Portrait and Landscape mode.

//How to Get the Height and Width of the Page on changing orientation in Windows Phone ?

protected override void OnOrientationChanged(OrientationChangedEventArgs e)

{

Dispatcher.BeginInvoke(delegate

{

MessageBox.Show(ActualHeight + " : " + ActualWidth);

});

base.OnOrientationChanged(e);

}

How to Get the Height and Width of the Page on changing orientation in Windows Phone?

0saves
If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Comment


x

You might be Interested in these Posts

How to delete user account from command line in Windows 10 ?

You can delete a user account from command line in Windows 10 using the net user command and specify...

How to add new user account from command line in Windows 10 ?

You can add a new user account in Windows 10 using command prompt using the net user command and pas...

How to open display settings from command line in Windows 10 ?

The display properties can be found in the settings app in Windows 10 which lets the users to config...