Enable Full Screen in Silverlight

Lets see how we can enable Full Screen in Silverlight .

Below is the Code attached for creating a Button . Clicking on the Button would enable Full Screen in Silverlight.

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
    {
        private double oldWidth;
        private double oldHeight;
        public double uniformScaleAmount = 1;
        public Page()
        {
            InitializeComponent();
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            oldHeight = this.Height;
            oldWidth = this.Width;
            Application.Current.Host.Content.Resized += new EventHandler(Content_Resized);
            Application.Current.Host.Content.FullScreenChanged += new EventHandler(Content_Resized);
        }

        private void LayoutRoot_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            Application.Current.Host.Content.IsFullScreen = !Application.Current.Host.Content.IsFullScreen;          
        }
        void Content_Resized(object sender, EventArgs e)
        {
            double currentWidth = Application.Current.Host.Content.ActualWidth;
            double currentHeight = Application.Current.Host.Content.ActualHeight;
            uniformScaleAmount = Math.Min((currentWidth / oldWidth), (currentHeight / oldHeight));
            RootLayoutScaleTransform.ScaleX = uniformScaleAmount;
            RootLayoutScaleTransform.ScaleY = uniformScaleAmount;
        }      
    }
}

Below is the Xaml code :
<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" Loaded="UserControl_Loaded">   
    <Canvas x:Name="LayoutRoot" Background="Gray" MouseLeftButtonDown="LayoutRoot_MouseLeftButtonDown">
        <Canvas.RenderTransform>
            <ScaleTransform ScaleX="1" ScaleY="1" x:Name="RootLayoutScaleTransform" />
        </Canvas.RenderTransform>
        <Rectangle Height="100" Width="100" Fill="#FFFFFFFF" Stroke="#FF000000" RadiusX="10" RadiusY="10" Stretch="Fill"/>
    </Canvas>
</UserControl>

Ebook Download
View all
Learn
View all