Sharker Khaleed Mahmud Silverlight Tips & Tricks

January 25, 2010

Tricks and Tips 20 : FullScreen Mode in Silverlight

This one is very simple. Fullscreen can be achieved in one line of code and using the same click event handler.

MainPage.xaml

<UserControl xmlns:my=”clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data”  x:Class=”Tips.MainPage”
    xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation
    xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml
    xmlns:d=”http://schemas.microsoft.com/expression/blend/2008
    xmlns:mc=”http://schemas.openxmlformats.org/markup-compatibility/2006
    mc:Ignorable=”d”
    d:DesignHeight=”300″ d:DesignWidth=”400″>
    <Grid x:Name=”LayoutRoot”>
        <Button x:Name=”btnFullScreen” Width=”100″ Height=”30″ Content=”OFF” />
    </Grid>
</UserControl>

MainPage.xaml.cs

using System.Windows;
using System.Windows.Controls;

namespace Tips
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            btnFullScreen.Click += new RoutedEventHandler(btnFullScreen_Click);
        }

        void btnFullScreen_Click(object sender, RoutedEventArgs e)
        {
            var btn = (Button)sender;
            App.Current.Host.Content.IsFullScreen = !App.Current.Host.Content.IsFullScreen;
           
            bool fullScreen = App.Current.Host.Content.IsFullScreen;
           
            if (fullScreen)
                btn.Content = “ON”;
            else
                btn.Content = “OFF”;
        }
    }
}

Sharker Khaleed Mahmud
Software Developer

No Comments Yet »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.