111 lines
		
	
	
		
			3.5 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			111 lines
		
	
	
		
			3.5 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 log4net.Repository.Hierarchy;
 | 
						|
using log4net;
 | 
						|
using System.Windows;
 | 
						|
 | 
						|
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 readonly ILog logger = LogManager.GetLogger(typeof(PortUtil));
 | 
						|
        public MainWindowViewModel(IRegionManager regionManager, IUnityContainer container, IEventAggregator eventAggregator, FingerprintUtil fingerprintUtil)
 | 
						|
        {
 | 
						|
            //_portUtil = portUtil;
 | 
						|
            this.eventAggregator = eventAggregator;
 | 
						|
            this.eventAggregator.GetEvent<SnackbarEvent>().Subscribe(doMyPrismEvent2);
 | 
						|
            _fingerprintUtil = fingerprintUtil;
 | 
						|
            _regionManager = regionManager;
 | 
						|
            _container = container;
 | 
						|
 | 
						|
            System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
 | 
						|
            {
 | 
						|
 | 
						|
                _container.RegisterType<object, LoginWindow>("LoginWindow");
 | 
						|
                _regionManager.RequestNavigate("MainRegion", "LoginWindow");
 | 
						|
 | 
						|
            }));
 | 
						|
 | 
						|
        }
 | 
						|
 | 
						|
        void doMyPrismEvent2(AlertMsg msg)
 | 
						|
        {
 | 
						|
            Application.Current.Dispatcher.BeginInvoke(() =>
 | 
						|
            {
 | 
						|
                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);
 | 
						|
            });
 | 
						|
        }
 | 
						|
 | 
						|
    }
 | 
						|
}
 |