前台頁面代碼:
<UserControl x:Class="SilverlightApplicationDome.fullScreenDome"
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" Background="White">
<Image Name="full" Source="img/3.jpg" Stretch="UniformToFill"></Image>
<Button Name="btnFull" Width="120" Height="80" Content="全屏顯示" FontSize="24" Click="btnFull_Click"></Button>
</Grid>
</UserControl>
其實很簡單,我們只需要引用命名空間,System.Windows.Interop就可以了。
後台代碼如下:
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;
using System.Windows.Interop;
namespace SilverlightApplicationDome
{
public partial class fullScreenDome : UserControl
{
public fullScreenDome()
{
InitializeComponent();
}
private void btnFull_Click(object sender, RoutedEventArgs e)
{
Content contentObject = Application.Current.Host.Content;
contentObject.IsFullScreen = !contentObject.IsFullScreen;
}
}