领胜LDS 键盘AOI检测项目
xcd
2020-06-24 d6c577e17ee7bb5331dd51d803f9b42441b0f0e5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using GalaSoft.MvvmLight.Ioc;
using GalaSoft.MvvmLight.Messaging;
using MahApps.Metro.Controls;
using MahApps.Metro.Controls.Dialogs;
using System;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using Bro.UI.Ctrls;
using Bro.UI.ViewModel;
 
namespace Bro.UI
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : MetroWindow
    {
        ManualResetEvent loadHandle = new ManualResetEvent(false);
 
        /// <summary>
        /// Initializes a new instance of the MainWindow class.
        /// </summary>
        public MainWindow()
        {
            Messenger.Default.Register<string>(this, "ProcessDone", OnProcessChanged);
 
            InitializeComponent();
 
            SimpleIoc.Default.Register<IDialogCoordinator>(() => DialogCoordinator.Instance, "Main");
 
            Closing += (s, e) =>
            {
                ViewModelLocator.Cleanup();
 
                (this.DataContext as MainViewModel)?.Cleanup();
 
                Messenger.Default.Unregister(this);
            };
 
            Closed += (s, e) => Application.Current.Shutdown();
 
            Loaded += (s, e) =>
              {
                  loadHandle.Set();
              };
        }
 
        private void OnProcessChanged(string obj)
        {
            Task.Run(() =>
            {
                loadHandle.WaitOne();
                runningViewBorder.Dispatcher.Invoke(() =>
                {
                    RunningView view = new RunningView();
                    view.Margin = new Thickness(3, 3, 3, 0);
                    runningViewBorder.Child = view;
                });
 
                gridInfo.Dispatcher.Invoke(() =>
                {
                    gridInfo.Children.Clear();
                    InformationCtrl infoCtrl = new InformationCtrl();
                    gridInfo.Children.Add(infoCtrl);
                });
            });
        }
    }
}