66 lines
2.4 KiB
C#
66 lines
2.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Interop;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Imaging;
|
|
using System.Windows.Shell;
|
|
|
|
namespace _29WxOrderWpf.BaseWindows
|
|
{
|
|
public class BaseWindow : Window
|
|
{
|
|
public BaseWindow()
|
|
{
|
|
//this.Icon = new BitmapImage(new Uri("pack://application:,,,/Resources/29wx.ico"));
|
|
this.Icon = Application.Current.Resources["main29WeixinIcon"] as ImageSource;
|
|
this.WindowStartupLocation = WindowStartupLocation.CenterScreen;
|
|
WindowChrome.SetWindowChrome(this, new WindowChrome() { CaptionHeight = 8, ResizeBorderThickness = new Thickness(4), });
|
|
|
|
this.DataContext = this;
|
|
this.Loaded += BaseWindow_Loaded;
|
|
|
|
SizeChanged += BaseWindow_SizeChanged;
|
|
}
|
|
|
|
private void BaseWindow_SizeChanged(object sender, SizeChangedEventArgs e)
|
|
{
|
|
if (WindowState == WindowState.Maximized)
|
|
{
|
|
//// 获取当前屏幕的工作区(排除任务栏)
|
|
//var workArea = SystemParameters.WorkArea;
|
|
|
|
//// 设置窗口位置和大小
|
|
//this.Left = workArea.Left;
|
|
//this.Top = workArea.Top;
|
|
//this.Width = workArea.Width;
|
|
//this.Height = workArea.Height;
|
|
this.Padding = new Thickness(6);
|
|
}
|
|
else
|
|
this.Padding = new Thickness(0);
|
|
}
|
|
|
|
private void BaseWindow_Loaded(object sender, RoutedEventArgs e)
|
|
{
|
|
if (SystemParameters.PrimaryScreenWidth < this.Width + 0)
|
|
this.Width = SystemParameters.PrimaryScreenWidth - 0;
|
|
if (SystemParameters.WorkArea.Height < this.Height + 0)
|
|
this.Height = SystemParameters.WorkArea.Height - 0;
|
|
|
|
this.MaxHeight = SystemParameters.WorkArea.Height + 14;
|
|
//this.MaxWidth = SystemParameters.WorkArea.Width + 13;
|
|
|
|
double screenWidth = SystemParameters.PrimaryScreenWidth;
|
|
double screenHeight = SystemParameters.WorkArea.Height;
|
|
double windowWidth = this.ActualWidth;
|
|
double windowHeight = this.ActualHeight;
|
|
this.Left = (screenWidth / 2) - (windowWidth / 2);
|
|
this.Top = (screenHeight / 2) - (windowHeight / 2);
|
|
}
|
|
}
|
|
}
|