3

I am working on a Silverlight 4 out of browser (OOB) application on a Windows 7 tablet PC. The majority of the time, the program is in full screen mode. However, if the user rotates the tablet, the application rotates and stays full screen, but is scaled for the previous screen orientation. Taking the application out of full screen and putting it back into full screen rescales everything correctly. Is there any way I can detect when the screen rotates? So far I've tried the app's Resize, LayoutChanged and FullScreenChanged events and have a handler for the main page's SizeChanged event. None of these get fired when the application is rotated in full screen mode.

Per Josh Einstein's suggestion, I tried polling the ActualWidth/Height of the application on a timer. It looks like after the rotation, the ActualWidth/Height values returned from the Silverlight plug-in are the pre-rotated values. Only taking it out of full screen and putting it back in full screen will change the resolution of the plug-in. The HtmlPage.Eval hack didn't work since I am OOB.

The WP7 version of Silverlight has the OnOrientationChanged event, which doesn't seem to be available in the desktop version. Anyone have any ideas?

bsruth
  • 5,372
  • 6
  • 35
  • 44

1 Answers1

1

Great question but as far as I can tell, it doesn't seem to be possible. I tried changing the screen resolution in a virtual machine (orientation change is really just a screen resolution change that results in width being larger than height or vice versa) and could not trigger any layout events.

The issue seems to be that the Silverlight plugin itself is not resized. With an elevated out-of-browser application you could presumably use COM interop with WMI to get the actual screen resolution, but it's kind of hacky. If it's an in-browser application, you could use the HTML DOM. In both cases, you'll probably have to poll for the current screen resolution instead of being notified via an event.

Mister Goodcat has written a blog post about how to get at this information in both scenarios.

I would file it as a Silverlight bug too.

Josh
  • 68,005
  • 14
  • 144
  • 156
  • Thanks, this gave be a brief moment of hope. Unfortunately it looks like the Silverlight plug-in doesn't correctly report the ActialWidth/Height after a screen rotation. See my updated question for more details. – bsruth May 26 '11 at 16:47
  • I know, in my answer I noted that after rotation, the Silverlight plugin is not resized. ActualHeight and ActualWidth will not give you the right values. You will need to look to WMI or HTML DOM for the values which requires either elevated out-of-browser or an in-browser app. – Josh May 27 '11 at 19:43
  • It seemed that the resizing issue was familiar. I spent most of my time on the post you linked to and just forgot about your original post. Sorry about that. – bsruth May 31 '11 at 20:51