前办场
<UserControl x:Class="ComputerDropDragControl.FullScreenButton"
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" HorizontalAlignment="Left">
<Button Content="全屏" x:Name="btnFullScreen" Click="btnFullScreen_Click"
Width="53" Height="30"
Margin="20,10,0,0" >
</Button>
</Grid>
</UserControl>
后半厂
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;//为什么要引入这个命名空间呢?Pay Attention to it.
namespace ComputerDropDragControl
{
public partial class FullScreenButton : UserControl
{
bool expand = false;
public FullScreenButton(UIElement uc)
{
InitializeComponent();
BackElement = uc;
Application.Current.Host.Content.FullScreenChanged += new EventHandler(Content_FullScreenChanged);
}
#region <<控件事件>>
#region <<全屏相关事件>>
private void btnFullScreen_Click(object sender, RoutedEventArgs e)
{
FullScreen();
}
private void FullScreen()
{
Content contentObject = Application.Current.Host.Content;
contentObject.IsFullScreen = !contentObject.IsFullScreen;
}
private void Content_FullScreenChanged(Object sender, EventArgs e)
{
Content contentObject = Application.Current.Host.Content;
if (contentObject.IsFullScreen)
{
Content_Resized(sender, e, true);
btnFullScreen.Background = new SolidColorBrush(Colors.Orange);
btnFullScreen.Content = "退出全屏";
}
else
{
Content_Resized(sender, e, false);
btnFullScreen.ClearValue(BackgroundProperty);
btnFullScreen.Content = "全 屏";
}
}
void Content_Resized(object sender, EventArgs e, bool fullScreen)
{
//double currentWidth = Application.Current.Host.Content.ActualWidth;
//double currentHeight = Application.Current.Host.Content.ActualHeight;
//uniformScaleAmount = Math.Min((currentWidth / width), (currentHeight / height));
//stackFather.Width = stackFather.ActualWidth * uniformScaleAmount;
//stackFather.Height = stackFather.ActualHeight * uniformScaleAmount;
//RootLayoutScaleTransform.ScaleX = uniformScaleAmount;
//RootLayoutScaleTransform.ScaleY = uniformScaleAmount;
//RootLayoutScaleTransformOne.ScaleX = uniformScaleAmount;
//RootLayoutScaleTransformOne.ScaleY = uniformScaleAmount;
ScrollViewer scrollOne = (ScrollViewer)BackElement;
if (fullScreen)
{
scrollOne.Width = Application.Current.Host.Content.ActualWidth;
scrollOne.Height = Application.Current.Host.Content.ActualHeight;
//this.scrollOne.Height = 700;
}
else
{
scrollOne.Width = 780;
scrollOne.Height = 720;
}
}
#endregion
#endregion
public UIElement BackElement { get; set; }
public double scrollWidth { get; set; }
}
}