Full screen Silverlight apps
At the end of last week, a question came up about whether Silverlight was capable of delivering apps that go beyond the browser frame. I thought I had recalled a sample that did this up on the Silverlight gallery but couldn't locate it, so I did a little more digging. I'm pleased to inform you that if you have a requirement for this, it's pretty simple and easy to do.
The trick lies in setting the Application.Current.Host.Content object's IsFullScreen property to true - the only thing you'll need to take note of is that the transition to full screen must be done in response to user input (for security reasons.) The following XAML + code illustrate (please don't mind the color scheme of the gradient fill.)
XAML:
<UserControl x:Class="AgFullScreen.Page"
xmlns="https://schemas.microsoft.com/client/2007"
xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml"
>
<Canvas x:Name="MyCanvas">
<Canvas.Background>
<LinearGradientBrush>
<GradientStop Offset="0" Color="Orange"/>
<GradientStop Offset="0.5" Color="Bisque"/>
<GradientStop Offset="1" Color="LightGreen"/>
</LinearGradientBrush>
</Canvas.Background>
<Button x:Name="MyButton" Canvas.Left="20" Canvas.Top="20" Content="Full Screen?" Height="50" Width="100"/>
<Button x:Name="MyOtherButton" Canvas.Left="20" Canvas.Top="120" Content="Not Full Screen?" Height="50" Width="100"/>
</Canvas>
</UserControl>
Code:
using System;
using System.Collections.Generic;
using System.Linq;
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 AgFullScreen
{
public partial class Page : UserControl
{
public Page()
{
InitializeComponent();
this.MyButton.Click += new RoutedEventHandler(MyButton_Click);
this.MyOtherButton.Click += new RoutedEventHandler(MyOtherButton_Click);
}
void MyButton_Click(object sender, RoutedEventArgs e)
{
//get the plugin content object
System.Windows.Interop.Content content = Application.Current.Host.Content;
content.IsFullScreen = true;
}
void MyOtherButton_Click(object sender, RoutedEventArgs e)
{
//get the plugin content object
System.Windows.Interop.Content content = Application.Current.Host.Content;
content.IsFullScreen = false;
}
}
}
Have fun with this, but please don't abuse full screen apps. :)