Preventing Silverlight applications from Scaling during resolution change

One of the problems faced by Silverlight applications is when the monitor resolution is not set to the native resolution. At a lower resolution, the application scales up and it can throw the layout calculations for your application into a tizzy!

In order to solve this, I thought of calculating the monitor’s maximum and current resolution and based on that scale the main page of the application. The search for getting the monitor resolution in silverlight led me here. It is a really nice article where the author describes of the various ways how to get the monitor resolution. I tried out the code to find that the code gives the current monitor resolution. There was no way I could find the maximum resolution of a given monitor.

Then I thought of getting the current DPI of the monitor and comparing it with 96 DPI to calculate the amount of scaling required to make the page look as if it was in native resolution.

The search to get the DPI led me to a site which provided the solution to the entire problem in just a single line!

Just add the following line in the Loaded event of the MainPage of your Silverlight application.

Application.Current.Host.Settings.EnableAutoZoom = false;

This solves the problem of scaling! No extra calculations required.

Advertisements

3 thoughts on “Preventing Silverlight applications from Scaling during resolution change

  1. Thanks!
    I was going crazy trying to find out why my web-application was scaling so strangely.
    Btw, I have this problem on my laptop where the resolution is the native resolution…

  2. Generally I don’t read post on blogs, however I
    wish to say that this write-up very forced me to try and do it!
    Your writing style has been surprised me. Thanks, very nice article.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s