Running in Full-Screen Mode

You can set your Silverlight application to run in full-screen mode if you wish, even when it is running inside the browser. This feature was designed to enable streaming video to be played on the full screen and for games, but you may find some uses for it in your business applications too, such as for kiosk applications. Let's take a look at how to do this.

Initiating Full-Screen Mode

The following code sets the application to run in full-screen mode:

Application.Current.Host.Content.IsFullScreen = true;

nce the application is in full-screen mode, the user can press the Escape key to go back to running normally. When the application enters full-screen mode, it will briefly flash a message telling the user of how to exit, as shown in Figure 16-11.

images

Figure 16-11. The message that briefly appears when entering full-screen mode

Alternatively, you can set the IsFullScreen property to false to return to normal mode programmatically. You will need to implement this when enabling full-screen mode when running with elevated trust, as the Escape key does not automatically exit full-screen in that scenario.

As with opening an open or save dialog or interacting with the clipboard, setting the application to display full screen must be a user-initiated action. That is, you can do so only from a Click event handler or similar, where the event is raised in response to user input. Attempting to do so otherwise, such as in the Loaded event of a page or view, will simply result in the action being ignored.

If the application is running with elevated trust, this limitation is lifted. In this scenario, you can set the application to run in full-screen mode from the application's Startup event or from the Loaded event or constructor of a page or view (for example) if you wish. However, when doing so from the application's Startup event or the constructor of the RootVisual, you must use the BeginInvoke command when setting the IsFullScreen property to true so that it does so on the user interface thread. Otherwise, it won't work. The following code demonstrates how to do this:

Deployment.Current.Dispatcher.BeginInvoke(() =>
    {
        Application.Current.Host.Content.IsFullScreen = true;
    });

Detecting the Switch to and from Full-Screen Mode

You can detect when the application has entered or left full-screen mode by handling the FullScreenChanged event on the Application.Current.Host.Content object, like so:

Application.Current.Host.Content.FullScreenChanged += Application_FullScreenChanged;

private void Application_FullScreenChanged(object sender, EventArgs e)
{
    // Full screen changed logic goes here
}

Retaining Full-Screen Mode When Unfocused

While the application is running in full-screen mode, attempting to switch to another application will take it back out to running in normal mode, either to its browser window or out-of-browser window. You can prevent this behavior so that it remains in full-screen mode, but with the other window in front of it, using the following code:

Application.Current.Host.Content.FullScreenOptions =
    System.Windows.Interop.FullScreenOptions.StaysFullScreenWhenUnfocused;

After setting this option, when you next attempt to go into full-screen mode, the user will be asked for permission to enable the application to remain in full-screen mode, regardless of other applications obtaining the focus, as shown in Figure 16-12.

images

Figure 16-12. The dialog asking whether it should be able to stay in full-screen mode

This message won't be displayed when the application is running in OOB mode with elevated trust.

images Note Unfortunately, unless the application is running with elevated trust, attempting to display an open or save dialog box will return the application to normal mode, even if the FullScreenOptions property is set to StaysFullScreenWhenUnfocused.

Keyboard Access

One of the primary limitations of full-screen mode is that the majority of keyboard input is disabled. This behavior is intended to prevent a rogue Silverlight application from impersonating the Windows lock screen (for example), where you may unintentionally enter your user credentials and have someone steal them from you. Mouse input will still work as normal in full-screen mode, as will the following keyboard keys: the arrow keys, space bar, and Tab, Page Up, Page Down, Home, End, and Enter keys. As mentioned earlier, the Escape key is captured by the Silverlight runtime and exits the full-screen mode.

Running with elevated trust lifts this restriction.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.119.114