using AutomaticApp.Base; using AutomaticApp.ViewModels; using AutomaticApp.Views; using System; using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.Windows.Threading; namespace AutomaticApp { /// /// Interaction logic for MainWindow.xaml /// public partial class MainWindow : Window { static public MainViewModel mainViewModel { set; get; } = new MainViewModel(); public Command DetailCommand { get; set; } public Command GoBackCommand { get; set; } private DispatcherTimer ShowTimer; public static ADCPDetailsModel aDCPDetailsModel = new ADCPDetailsModel(); public static ADCPDetailsModel aDCPDetailsModel2 = new ADCPDetailsModel(); public MainWindow() { InitializeComponent(); //this.DataContext = mainViewModel; //mainViewModel.PageContent = new MonitorView(); this.DataContext = mainViewModel; this.MaxHeight = SystemParameters.PrimaryScreenHeight;//防止最大化时系统任务栏被遮盖 //添加timer ShowTimer = new System.Windows.Threading.DispatcherTimer(); ShowTimer.Tick += new EventHandler(showTimer); ShowTimer.Interval = new TimeSpan(0, 0, 0, 1, 0); ShowTimer.Start(); DetailCommand = new Command(DoDetailCommand); GoBackCommand = new Command(DoGoBackCommand); //打开软件前进行各个接口的连接 mainViewModel.DoComConnect(null); mainViewModel.DoSocket1Connect(null); mainViewModel.DoSocket2Connect(null); } //日期 public void showTimer(object sender, EventArgs e) { this.Datatime.Text = ""; this.Date.Text = ""; this.week.Text = ""; //获得年月日 //this.Datatime.Text += " " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); //yyyy年MM月dd日 this.Datatime.Text += " " + DateTime.Now.ToString("HH:mm:ss"); //yyyy年MM月dd日 this.Date.Text += " " + DateTime.Now.ToString("yyyy-MM-dd"); this.week.Text += System.DateTime.Today.ToString("dddd", new System.Globalization.CultureInfo("zh-CN")); } /// /// 顶部蓝色区域按钮按下事件 /// /// /// private void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed) this.DragMove(); switch (e.ClickCount) { case 2: { WindowState = WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized; break; } } } /// /// 打开详情页---接驳盒站点1# adcp详情 /// /// private void DoDetailCommand(object obj) { ADCPDetailsView view = new ADCPDetailsView(); //object view = new object(); if (Convert.ToInt32(obj) == 1) { view.DataContext = aDCPDetailsModel; } else if(Convert.ToInt32(obj) == 2) { view.DataContext = aDCPDetailsModel2; } mainViewModel.PageContent = (FrameworkElement)view; // 位移 ThicknessAnimation thicknessAnimation = new ThicknessAnimation( new Thickness(0, 50, 0, -50), new Thickness(0, 0, 0, 0), new TimeSpan(0, 0, 0, 0, 400)); // 透明度 DoubleAnimation doubleAnimation = new DoubleAnimation(0, 1, new TimeSpan(0, 0, 0, 0, 400)); Storyboard.SetTarget(thicknessAnimation, (FrameworkElement)view); Storyboard.SetTarget(doubleAnimation, (FrameworkElement)view); Storyboard.SetTargetProperty(thicknessAnimation, new PropertyPath("Margin")); Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("Opacity")); Storyboard storyboard = new Storyboard(); storyboard.Children.Add(thicknessAnimation); storyboard.Children.Add(doubleAnimation); storyboard.Begin(); } /// /// 返回主界面 /// /// private void DoGoBackCommand(object obj) { //ConboxPageView conboxPageView = new ConboxPageView(); //mainViewModel.PageContent = conboxPageView; mainViewModel.DoNavChanged(""); // 透明度 DoubleAnimation doubleAnimation = new DoubleAnimation(0, 1, new TimeSpan(0, 0, 0, 0, 400)); Storyboard.SetTarget(doubleAnimation, mainViewModel.PageContent); Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("Opacity")); Storyboard storyboard = new Storyboard(); storyboard.Children.Add(doubleAnimation); storyboard.Begin(); } /// /// 主窗口关闭 /// /// /// private void Button_Click(object sender, RoutedEventArgs e) { this.Close(); } /// /// 最大化按钮 /// private void MaxButton_Click(object sender, RoutedEventArgs e) { this.WindowState = this.WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized; } /// /// 最小化按钮 /// private void MinButton_Click(object sender, RoutedEventArgs e) { this.WindowState = WindowState.Minimized; } private void Button_Click_1(object sender, RoutedEventArgs e) { } } }