Going Full Screen
       by kirupa  |  17 June 2008

Most commonly, you interact with your Silverlight application as a component as part of a larger web page. There are many cases, though, where you would want your undivided attention to be paid to your Silverlight application - such as when you are watching a movie or playing with some Deep Zoom content.

In those cases, you can give your users the ability to run your application in full screen. To see an example of what this looks like, click on the Full Screen button in the below example:

Get Microsoft Silverlight

When you clicked on the Toggle Full Screen button, your Silverlight application will have gone, as expected, full screen where your taskbar, browser buttons, etc. are all hidden from view. Clicking the button again will return you back to the application's default size.

 The code for doing this is fairly straightforward:

private void GoFullScreen(object sender, RoutedEventArgs e)
{
if (!Application.Current.Host.Content.IsFullScreen)
{
Application.Current.Host.Content.IsFullScreen = true;
}
else
{
Application.Current.Host.Content.IsFullScreen = false;
}
}

The code can be summarized as follows. You check to see whether you are currently in full screen mode. If you are not, then you switch into full screen mode. If you are already in full screen mode, then you will return to your default, non-full screen view.

Let's look a the code in greater detail:

if (!Application.Current.Host.Content.IsFullScreen)
{
Application.Current.Host.Content.IsFullScreen = true;
}
else
{
Application.Current.Host.Content.IsFullScreen = false;
}

In the above line, I have an if statement that checks whether you are currently in full screen mode or not. I accomplish that via checking what the value of Application.Current.Host.Content.IsFullScreen is. This statement returns a true or false depending on whether your application is in full screen or not.

I am not doing a straightforward comparison. I am actually negating the value returned by the IsFullScreen property by using the ! (exclamation mark). What this if statement actually says is "If Application is NOT Full Screen" then do something, otherwise, do something else.


When your if statement determines you are not currently in full screen mode, the following line gets executed:

if (!Application.Current.Host.Content.IsFullScreen)
{
Application.Current.Host.Content.IsFullScreen = true;
}
else
{
Application.Current.Host.Content.IsFullScreen = false;
}

This line simply sets your IsFullScreen property to true. Once this happens, you automatically go into full screen mode. There is nothing extra you have to do.


If you were already in full screen mode when you called your if statement, your if statement will return a false and send you to the following line of code:

if (!Application.Current.Host.Content.IsFullScreen)
{
Application.Current.Host.Content.IsFullScreen = true;
}
else
{
Application.Current.Host.Content.IsFullScreen = false;
}

In this line, we are setting our IsFullScreen property to false, and this returns your view back to its original state where your Silverlight application is back to its normal size.

Keyboard and Mouse in Full Screen
When you are in full screen mode, though, your keyboard and mouse functionality is reduced for security reasons. You only have mouse button, arrow keys, and space bar support. You do not have the ability to use other keys on your keyboard or the mouse wheel.


Just a final word before we wrap up. If you have a question and/or want to be part of a friendly, collaborative community of over 220k other developers like yourself, post on the forums for a quick response!

Kirupa's signature!





SUPPORTERS:

kirupa.com's fast and reliable hosting provided by Media Temple.