How to tell the screen resolution from within a Silverlight app
There isn't a direct API for detecting the screen width and height from within a Silverlight app. Fortunately, JavaScript provides you a way, viz. via the screen.width
and screen.height
properties. So with a nifty use of Silverlight's HTML DOM Bridge, these values can be read with little issue.
int screenWidth = Int32.Parse(
HtmlPage.Window.Eval("screen.width").ToString()
);
int screenHeight = Int32.Parse(
HtmlPage.Window.Eval("screen.height").ToString()
);
Then when your app runs in fullscreen mode, you'd get the screen resolution using the Silverlight plug-in's ActualWidth and ActualHeight.
int screenWidth =
Application.Current.Host.Content.ActualWidth;
int screenHeight =
Application.Current.Host.Content.ActualHeight;
Labels: Silverlight
2 Comments:
How do you detect that you are running full screen in Silverlight?
By Anonymous, at August 11, 2008 at 12:13 AM
Hi I am getting error like this.
The DOM/scripting bridge is disabled.
By Anonymous, at January 15, 2011 at 3:19 AM
Post a Comment | Home | Inference: my personal blog