CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Language: C#

Silverlight 4 FullScreen Command

1469 Views
Copy Code Show/Hide Line Numbers
public class FullScreenCommand : ICommand
{
    public event EventHandler CanExecuteChanged;
 
    public bool CanExecute(object parameter)
    {
        bool isFullScreen = (bool.TryParse(parameter.ToString(), out isFullScreen)) ? isFullScreen : true;
 
        return Application.Current.Host.Content.IsFullScreen != isFullScreen;
    }
 
    public void Execute(object parameter)
    {
        bool isFullScreen = (bool.TryParse(parameter.ToString(), out isFullScreen)) ? isFullScreen : true;
 
        Application.Current.Host.Content.FullScreenOptions = FullScreenOptions.StaysFullScreenWhenUnfocused;
        Application.Current.Host.Content.IsFullScreen = isFullScreen;
    }
 
    public FullScreenCommand()
    {
        Application.Current.Host.Content.FullScreenChanged += (s, e) =>
        {
            EventHandler handler = CanExecuteChanged;
            if (handler != null)
            {
              handler(this, EventArgs.Empty);
            }
        };
    }
}
by Andrej Tozon
  March 18, 2010 @ 8:49am
Tags:
Description:
Usage: <Button Command="{Binding FullScreenCommand}" CommandParameter="True">Full Screen</Button>

Add a comment


Report Abuse
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate