Silverlight 2.0: Project template for self-resizing applications (update)

.NET, Silverlight, Technical stuff
See comments

An observant reader gave me a better way to automatically resize a Silverlight application. The way I published in my last post was inspired from Silverlight 1.0, where JavaScript is obviously needed to do the job. However, in 2.0, you can register for a CLR event and avoid the multiple conversions between JavaScript and C#. These conversions take time and it’s better to avoid them when possible. I modified the Project Template accordingly. You can download the updated version here, and follow the installation procedure here.

The resizing operation is simpler now, since everything occurs in C#. It is as simple as registering for the BrowserHost.Resize event. This event is raised automatically when the application starts up, so no need to call it explicitly. In the event handler, simply calculate the factor (based on the initial dimensions) with which the ScaleTransform must be applied.

The template also takes care of centering the application horizontally, and of registering the main Canvas with the browser host, so that public Scriptable methods can be called from JavaScript. Like in the previous version, you can also pass the page’s URL and other parameters to construct the Silverlight application, in order to make it easier to place the same application on multiple web pages.

Previous entry | Next blog entry

Comments for Silverlight 2.0: Project template for self-resizing applications (update)