Silverlight Tip of the Day #35 – Full Screen Mode Implementation
To have your application enter into full screen mode all you have to do is execute the following line of code:
Application.Current.Host.Content.IsFullScreen = true;
Once in full screen Silverlight will briefly show the following message that will fade away in a few seconds:
At this point the <ESC> key is reserved for exiting out of full screen mode. Of course, you can also exit manually by setting IsFullScreen = false.
Limitations/Restrictions to be aware of:
- For security reasons, you cannot set the property IsFullScreen directly but rather only in the response to a user input event such as a button click.
- To prevent password spoofing, only the following keyboard inputs are allowed while in full screen mode:
- space
- arrow keys
- tab
- home
- enter
- end
- pageup/pagedown
Run a complete demo here: http://silverlight.services.live.com/invoke/66033/Full%20Screen/iframe.html
Sample Source for Page.xaml.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace FullScreen
{
public partial class Page : UserControl
{
public Page()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
ToggleFullScreen();
}
private void ToggleFullScreen()
{
Application.Current.Host.Content.IsFullScreen = !Application.Current.Host.Content.IsFullScreen;
}
}
}
Page.xaml:
<UserControl x:Class="FullScreen.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<Canvas>
<Button Click="Button_Click" Content="Toggle Full Screen"></Button>
</Canvas>
</UserControl>
Thank you,
--Mike Snow
Subscribe in a reader