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.


Did You Like This?

Getting Help

If you have questions, need some assistance on this topic, or just want to chat - post in the comments below or drop by our friendly forums (where you have a lot more formatting options) and post your question. There are a lot of knowledgeable and witty people who would be happy to help you out

Share

Did you enjoy reading this and found it useful? If so, please share it with your friends:

If you didn't like it, I always like to hear how I can do better next time. Please feel free to contact me directly at kirupa[at]kirupa.com.

Cheers!

Kirupa Chinnathambi

 

Add Your Comment (or post on the Forums)

add your comment

  

Read-only Archive of Old comments

Below is an archive of old comments made on this article. To create new comments click on the Start or Continue Discussion text above to add to this list.

blog comments powered by Disqus




SUPPORTERS:

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