Tip of the Day #9 – Browser Resize – How to capture the size of your browser when it is resized.
Now that Beta 2 is almost out the door I will start delivering more tutorials related to game development. I apologize for the delay but I have been swamped!
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 your align your elements to the browsers borders, center your character on the screen, etc.
In Beta1 there was a BrowserHost object that could be used but is no longer available in Beta2. For Beta 2, 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:
1: void Content_Resized(object sender, EventArgs e)
2: {
3: double height = App.Current.Host.Content.ActualHeight;
4: double width = App.Current.Host.Content.ActualHeight;
5: }
Thank you,
--Mike Snow
Subscribe in a reader