Silverlight 4 FullScreen Command

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);
            }
        };
    }
}
posted @ 2011-06-11 17:01  zhh  阅读(150)  评论(0编辑  收藏  举报