I've been working a bit more on Silverlight so here is another quick tip on it. This time it's about supporting the fullscreen mode of a Silverlight application.
ScottGu wrote about this topic back in early days of Silverlight 1.1 (Tip/Trick: Supporting Full Screen Mode with Silverlight) but I had a few problems implementing it: I tried to send my application in Full Screen mode handling an event raised by a control on my HTML page but the IsFullScreen property didn't want to go to true.
Let's first see how to send a Silverlight application in FullScreen mode:
private void OnFullScreenClicked(object sender, MouseEventArgs e) { BrowserHost.IsFullScreen = true; }
This code can be called from everywhere: Scott added is as handler for the MouseLeftButtonUp event of Silverlight canvas element:
Canvas fsBox = FindName("fullScreen") as Canvas; fsBox.MouseLeftButtonUp += OnFullScreenClicked;
while I did the same, but with a HTML button:
HtmlDocument doc = HtmlPage.Document; HtmlElement btnFs = doc.GetElementByID("btnFullScreen"); btnFs.AttachEvent("onclick", OnFullScreenClicked);
But I found out that my version didn't work: even after having set the true, the IsFullScreen property always stayed false.
After a bit of testing I found out that the Full Screen mode cannot be changed if the event that triggers it comes from the HTML/JavaScript side of the application.
Not sure if this a bug or a security feature, but if you find yourself in the need of send your Silverlight application to Full Screen, do it from a control inside the app.