后台
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
{
//设置“最外层滚动条”信息
double browseWidth = Application.Current.Host.Content.ActualWidth;//SilverLight控件所在浏览器确定的宽度
double browseHeight = Application.Current.Host.Content.ActualHeight;
scrollOne.Width = browseWidth - 400;
scrollOne.Height = browseHeight - 200;
}
}
#endregion
#endregion
public UIElement BackElement { get; set; }
public double scrollWidth { get; set; }
}
}