Windows Phone Developer Tips

General Windows Phone developer tips including but limited to game programming tips. Also, general Silverlight news and announcements.

Silverlight Tip of the Day #9 – How to Capture the Size of your Browser when it is Resized.

Silverlight Tip of the Day #9 – How to Capture the Size of your Browser when it is Resized.

  • Comments 1

[Blog Mirrored from http://silverlight.net/blogs/msnow/default.aspx]

For this tutorial, I will be showing you how to capture the size of your browser when it is resized. This is essential if you want to align your elements to the browsers borders, center your character on the screen, etc.

To accomplish this we will simply attach a resized event handler for the App.Current.Host.Content object.

Page.xaml.cs:

public Page()
{
    InitializeComponent();
 
    App.Current.Host.Content.Resized += new EventHandler(Content_Resized);
}

From here, we can capture the size of your browser when it changes:

void Content_Resized(object sender, EventArgs e)
{
     double height = App.Current.Host.Content.ActualHeight;
     double width = App.Current.Host.Content.ActualWidth;
}

Thank you,
--Mike Snow

 Subscribe in a reader

Comments
Leave a Comment
  • Please add 3 and 6 and type the answer here:
  • Post