Preventing Silverlight applications from Scaling during resolution change
June 3, 2011 Leave a comment
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.
Recent Comments