using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; using HighWayIot.Log4net; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; namespace Aucma.Scada.UI.viewModel { public class MainViewModel : ViewModelBase { private LogHelper logHelper = LogHelper.Instance; private readonly LogInfoControl logInfoControl = new LogInfoControl(); private readonly IndexControl indexControl = new IndexControl(); private readonly RecordControl recordControl = new RecordControl(); public MainViewModel() { //FormControlCommand = new RelayCommand(obj=> FormControl(obj)); //OpenSystemKeyboardCommand = new RelayCommand(OpenSystemKeyboard); } #region 参数定义 private int _PresentColor = 0; public int PresentColor { get { return _PresentColor; } set { _PresentColor = value; RaisePropertyChanged(nameof(PresentColor)); } } public System.Windows.Controls.UserControl _content; public System.Windows.Controls.UserControl UserContent { get { return _content; } set { _content = value; RaisePropertyChanged(nameof(UserContent)); } } #endregion #region 事件定义 /// /// 界面跳转按钮事件 /// private RelayCommand _controlOnClickCommand; public RelayCommand ControlOnClickCommand { get { if (_controlOnClickCommand == null) _controlOnClickCommand = new RelayCommand(obj=> ControlOnClick(obj)); return _controlOnClickCommand; } set { _controlOnClickCommand = value; RaisePropertyChanged(nameof(ControlOnClickCommand)); } } /// /// 逻辑实现 /// private void ControlOnClick(object obj) { try { string info = obj as string; switch (info) { case "inde": UserContent = indexControl; break; case "logInfo": UserContent = logInfoControl; break; case "record": UserContent = recordControl; break; default: break; } }catch(Exception ex) { logHelper.Error("界面跳转逻辑异常", ex); } } /// /// 打开系统键盘 /// private RelayCommand _openSystemKeyboardCommand; public RelayCommand OpenSystemKeyboardCommand { get { if (_openSystemKeyboardCommand == null) _openSystemKeyboardCommand = new RelayCommand(OpenSystemKeyboard); return _openSystemKeyboardCommand; } set { _openSystemKeyboardCommand = value; RaisePropertyChanged(nameof(OpenSystemKeyboardCommand)); } } /// /// 逻辑实现 /// public void OpenSystemKeyboard() { try { MessageBox.Show("打开系统键盘"); }catch(Exception ex) { logHelper.Error("打开系统键盘逻辑异常", ex); } } /// /// 窗体控制 /// private RelayCommand _formControlCommand; public RelayCommand FormControlCommand { get { if (_formControlCommand == null) _formControlCommand = new RelayCommand(obj => FormControl(obj)); return _formControlCommand; } set { _formControlCommand = value; RaisePropertyChanged(nameof(FormControlCommand)); } } /// /// 逻辑实现 /// /// public void FormControl(object obj) { try { string controlType = obj as string; switch (controlType) { // 关闭当前窗口 case "Exit": //Environment.Exit(0); Application.Current.Shutdown(); break; // 还原 或者 最大化当前窗口 case "Normal": if (Application.Current.MainWindow.WindowState == WindowState.Normal) { Application.Current.MainWindow.WindowState = WindowState.Maximized; break; } if (Application.Current.MainWindow.WindowState == WindowState.Maximized) { Application.Current.MainWindow.WindowState = WindowState.Normal; break; } break; // 最小化当前窗口 case "Minimized": Application.Current.MainWindow.WindowState = WindowState.Minimized; break; default: break; } }catch(Exception ex) { logHelper.Error("窗体控制逻辑异常", ex); } } #endregion } }