Silverlight supports fullscreen mode

Silverlight 2 has build in support  for fullscreen mode.This feature can be very interested for building same online game solution or some cool video players or …When we enter to this fullscreen mode everything is hidden including browser frame.

We can also resize our application to fit new changed screen size using two events in

Application.Current.Host.Content class.This class is located in C:\Program Files\Microsoft SDKs\Silverlight\v2.0\Reference Assemblies\System.Windows.dll and it looks like this :

        public sealed class Content

        {

            // Fields

 

            private EventHandler FullScreenChanged;

            private EventHandler Resized;

 

            // Events

 

            public event EventHandler FullScreenChanged;

            public event EventHandler Resized;

 

            // Methods

 

            public Content();

 

            internal void FireFullScreenChanged(object sender, EventArgs args);

            internal void FireResized(object sender, EventArgs args);

 

            // Properties

 

            public double ActualHeight { get; }

            public double ActualWidth { get; }

            public bool IsFullScreen { get; set; }

        }


You will see on little demo project how this works in real life. First we need to add ScaleTransform in Page xaml code:

ScaleTransform ScaleX=“1” ScaleY=“1” x:Name=“Root”

 After that on Load method we need to save original width and height of application before entering fullscreen mode.We declare two variables to hold this values

private double width;

private double height;

 and we set values:

 private void Load(object sender, RoutedEventArgs e)

        {

            height = this.Height;

            width = this.Width;

            Application.Current.Host.Content.Resized += new EventHandler(Resized);

            Application.Current.Host.Content.FullScreenChanged += new EventHandler(Resized);

        }

 We add one method Resized to handle both our events  Application.Current.Host.Content.Resized and  Application.Current.Host.Content.FullScreenChanged and inside this method we set how much application will resize on entering fullscreen mode by divide ActualWidth with old width and ActualHeight with old height.  

private void Resized(object sender, EventArgs e)

        {

            if (Application.Current.Host.Content.IsFullScreen)

            {

                //if is fullscreen then zoom

                Root.ScaleX = (Application.Current.Host.Content.ActualWidth / width);

                Root.ScaleY = (Application.Current.Host.Content.ActualHeight / height);

            }

            else

            {

                //exit fullscreen remove zoom

                Root.ScaleX = 1;

                Root.ScaleY = 1;

            }

        }

 And finally we add some button to change mode from fullscreen to normal on button click

private void Button_Click(object sender, RoutedEventArgs e)

        {

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

        }

 NotFullScreen
 

Fullscreen

Demo project : SilverlightFullscreenDemo

Comments are closed.