106 lines
3.4 KiB
C#
106 lines
3.4 KiB
C#
using MaterialDesignThemes.Wpf;
|
|
using Prism.Commands;
|
|
using Prism.Events;
|
|
using Prism.Mvvm;
|
|
using Prism.Regions;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Media;
|
|
using DM_Weight.msg;
|
|
using DM_Weight.Port;
|
|
using DM_Weight.util;
|
|
using DM_Weight.Finger;
|
|
using DM_Weight.Views;
|
|
using Unity;
|
|
using DM_Weight.HIKVISION;
|
|
|
|
namespace DM_Weight.ViewModels
|
|
{
|
|
internal class MainWindowViewModel : BindableBase
|
|
{
|
|
private string _title = "Prism App"; //标题
|
|
|
|
private ISnackbarMessageQueue _snackbarMessageQueue = new SnackbarMessageQueue(TimeSpan.FromSeconds(3));
|
|
|
|
private SolidColorBrush _colorBrush;
|
|
|
|
|
|
//private PortUtil _portUtil;
|
|
|
|
private ScreenUtil _screenUtil;
|
|
|
|
public SolidColorBrush Background
|
|
{
|
|
get => _colorBrush;
|
|
set => SetProperty(ref _colorBrush, value);
|
|
}
|
|
|
|
public ISnackbarMessageQueue SnackbarMessageQueue
|
|
{
|
|
get => _snackbarMessageQueue;
|
|
set => SetProperty(ref _snackbarMessageQueue, value);
|
|
}
|
|
public string Title
|
|
{
|
|
get { return _title; }
|
|
set { SetProperty(ref _title, value); }
|
|
}
|
|
|
|
|
|
IEventAggregator eventAggregator;
|
|
|
|
|
|
//public MainWindowViewModel(IEventAggregator eventAggregator, PortUtil portUtil, ScreenUtil screenUtil)
|
|
//{
|
|
// _portUtil = portUtil;
|
|
// this.eventAggregator = eventAggregator;
|
|
// this.eventAggregator.GetEvent<SnackbarEvent>().Subscribe(doMyPrismEvent2);
|
|
// _screenUtil = screenUtil;
|
|
//}
|
|
//private FingerprintUtil _fingerprintUtil;
|
|
IRegionManager _regionManager;
|
|
IUnityContainer _container;
|
|
//private CHKFunction _cHKFunction;
|
|
public MainWindowViewModel(IRegionManager regionManager, IUnityContainer container, IEventAggregator eventAggregator)
|
|
{
|
|
//_portUtil = portUtil;
|
|
this.eventAggregator = eventAggregator;
|
|
this.eventAggregator.GetEvent<SnackbarEvent>().Subscribe(doMyPrismEvent2);
|
|
//_fingerprintUtil = fingerprintUtil;
|
|
_regionManager = regionManager;
|
|
_container = container;
|
|
//_cHKFunction = cHKFunction;
|
|
System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
|
|
{
|
|
|
|
//_container.RegisterType<object, LoginWindow>("LoginWindow");
|
|
//_regionManager.RegisterViewWithRegion("MainRegion", "LoginWindow");
|
|
|
|
_regionManager.RequestNavigate("MainRegion", "LoginWindow");
|
|
|
|
}));
|
|
}
|
|
|
|
void doMyPrismEvent2(AlertMsg msg)
|
|
{
|
|
switch (msg.Type)
|
|
{
|
|
case MsgType.INFO:
|
|
this.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#00e676"));
|
|
break;
|
|
case MsgType.ERROR:
|
|
this.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c"));
|
|
break;
|
|
default:
|
|
this.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#00e676"));
|
|
break;
|
|
}
|
|
SnackbarMessageQueue.Enqueue(msg.Message);
|
|
}
|
|
|
|
}
|
|
}
|