领胜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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
using System;
using System.Collections.Generic;
using System.Linq;
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.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
 
namespace Bro.UI.Ctrls
{
    /// <summary>
    /// OperationCtrl.xaml 的交互逻辑
    /// </summary>
    public partial class OperationCtrl : UserControl
    {
        public OperationCtrl()
        {
            InitializeComponent();
        }
 
        public static readonly DependencyProperty IsRunningProperty;
        public bool IsRunning
        {
            get => (bool)GetValue(IsRunningProperty);
            set => SetValue(IsRunningProperty, value);
        }
 
        public static RoutedEvent RunEvent;
        public static RoutedEvent StopEvent;
        public static RoutedEvent LoadEvent;
 
        public event RoutedEventHandler RunHandler
        {
            add { AddHandler(RunEvent, value); }
            remove { RemoveHandler(RunEvent, value); }
        }
 
        public event RoutedEventHandler StopHandler
        {
            add { AddHandler(StopEvent, value); }
            remove { RemoveHandler(StopEvent, value); }
        }
 
        public event RoutedEventHandler LoadHandler
        {
            add { AddHandler(LoadEvent, value); }
            remove { RemoveHandler(LoadEvent, value); }
        }
 
        static OperationCtrl()
        {
            RunEvent = EventManager.RegisterRoutedEvent("RunHandler", RoutingStrategy.Direct, typeof(RoutedEventHandler), typeof(OperationCtrl));
            StopEvent = EventManager.RegisterRoutedEvent("StopHandler", RoutingStrategy.Direct, typeof(RoutedEventHandler), typeof(OperationCtrl));
            LoadEvent = EventManager.RegisterRoutedEvent("LoadHandler", RoutingStrategy.Direct, typeof(RoutedEventHandler), typeof(OperationCtrl));
 
            IsRunningProperty = DependencyProperty.Register("IsRunning", typeof(bool), typeof(OperationCtrl), new PropertyMetadata(false, OnIsRunningPropertyChanged));
        }
 
        private static void OnIsRunningPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            OperationCtrl ctrl = d as OperationCtrl;
            if (ctrl != null)
            {
                bool isRunning = (bool)e.NewValue;
                ctrl.btnRun.IsChecked = isRunning;
                ctrl.txtRun.Text = isRunning ? "停止" : "启动";
                ctrl.icoRun.Kind = isRunning ? MahApps.Metro.IconPacks.PackIconFontAwesomeKind.StopSolid : MahApps.Metro.IconPacks.PackIconFontAwesomeKind.PlaySolid;
 
                ctrl.btnLoad.IsEnabled = !isRunning;
 
                if (isRunning)
                {
                    ctrl.col1.Width = GridLength.Auto;
                    ctrl.btnLoad.Visibility = Visibility.Collapsed;
                }
                else
                {
                    ctrl.col1.Width = new GridLength(1, GridUnitType.Star);
                    ctrl.btnLoad.Visibility = Visibility.Visible;
                }
            }
        }
 
        private void btnLoad_Click(object sender, RoutedEventArgs e)
        {
            RaiseEvent(new RoutedEventArgs(LoadEvent, this));
        }
 
        private void btnRun_Click(object sender, RoutedEventArgs e)
        {
            btnRun.IsChecked = !btnRun.IsChecked;
 
            if (btnRun.IsChecked ?? true)
            {
                RaiseEvent(new RoutedEventArgs(StopEvent, this));
            }
            else
            {
                RaiseEvent(new RoutedEventArgs(RunEvent, this));
            }
        }
    }
}