Silverlight Tip of the Day #9 – How to Capture the Size of your Browser when it is Resized.
[Blog Mirrored from https://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
Comments
- Anonymous
November 18, 2008
PingBack from http://mstechnews.info/2008/11/silverlight-tip-of-the-day-9-%e2%80%93-how-to-capture-the-size-of-your-browser-when-it-is-resized/