using System;
using System.Threading;
using System.Windows;
using System.Windows.Input;
using System.Windows.Threading;
using LampInspectionMachine.Log4xml;
namespace LampInspectionMachine.Views
{
///
/// MainWindow.xaml 的交互逻辑
///
public partial class MainWindow : Window
{
private WindowState _windowState= WindowState.Normal;
public MainWindow()
{
InitializeComponent();
}
Rect rcnormal;//定义一个全局rect记录还原状态下窗口的位置和大小。
///
/// 最大化
///
private void btnMaximize_Click(object sender, RoutedEventArgs e)
{
if ( _windowState == WindowState.Normal )
{
_windowState = WindowState.Maximized;
rcnormal = new Rect(this.Left, this.Top, this.Width, this.Height);//保存下当前位置与大小
this.Left = 0;//设置位置
this.Top = 0;
Rect rc = SystemParameters.WorkArea;//获取工作区大小
this.Width = rc.Width;
this.Height = rc.Height;
}
else
{
_windowState = WindowState.Normal;
Rect rc = SystemParameters.WorkArea;//获取工作区大小
this.Width = rc.Width/2;
this.Height = rc.Height/2;
this.Left = rc.Left / 2;
this.Top = rc.Top / 2;
}
}
///
/// 还原
///
private void btnNormal_Click(object sender, RoutedEventArgs e)
{
this.WindowState = WindowState.Minimized;
}
private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
{
//if (this.ActualHeight > SystemParameters.WorkArea.Height || this.ActualWidth > SystemParameters.WorkArea.Width)
//{
// this.WindowState = System.Windows.WindowState.Normal;
// btnMaximize_Click(null, null);
//}
System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
Thread.Sleep(500);
this.InvalidateVisual();
this.UpdateLayout();
}));
}
private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
{
if ( e.ClickCount == 2 )
{
if ( this.ActualWidth == SystemParameters.WorkArea.Width )
{
btnNormal_Click(null, null);
}
else
{
btnMaximize_Click(null, null);
}
}
}
private void Button_Click(object sender, RoutedEventArgs e)
{
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
}
}
}