Daily Demo: Silverlight Fullscreen Trigger Action
A common needed and used feature in Silverlight is the Fullscreen Mode. A feature to switch the current application from a hosted in browser to fullscreen mode. This features is interesting in scenarios like Point of Sales- or Games-Applications.
Normal Browser Mode
Full Screen Mode
XAML-Code
<UserControl x:Class="FullScreenBehavior.MainPage"
xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="https://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="https://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:TheOliver_Controls="clr-namespace:TheOliver.Controls"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
d:DesignHeight="300" d:DesignWidth="400">
<Grid x:Name="LayoutRoot" Background="White">
<Button
Content="Button"
Height="23"
HorizontalAlignment="Left"
Margin="10,10,0,0"
Name="button1"
VerticalAlignment="Top"
Width="75">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<TheOliver_Controls:FullScreenAction/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
<Rectangle Stroke="Black" Margin="155,113,141,110">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonUp">
<TheOliver_Controls:FullScreenAction/>
</i:EventTrigger>
</i:Interaction.Triggers>
<Rectangle.Fill>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0"/>
<GradientStop Color="White" Offset="1"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
</Grid>
</UserControl>
Sourcecode
// Copyright © Microsoft Corporation. All Rights Reserved.
// This code released under the terms of the
// Microsoft Public License (MS-PL, https://opensource.org/licenses/ms-pl.html.)
using System.Windows;
using System.Windows.Interactivity;
namespace TheOliver.Controls
{
public class FullScreenAction : TargetedTriggerAction<FrameworkElement>
{
protected override void Invoke(object o)
{
Application.Current.Host.Content.IsFullScreen =
!Application.Current.Host.Content.IsFullScreen;
}
}
}