Monday, September 26, 2011

How to get the current screen resolution in Silverlight

To get the screen resultion in silverlight we can use the browser's window object. The browser window object is HtmlPage.Window. The namespace under which the HtmlPage comes is System.Windows.Browser.
Here is the code to find out the width and height according to current screen resolution.

string width = HtmlPage.Window.Eval("screen.width").ToString();
string height = HtmlPage.Window.Eval("screen.height").ToString();