领胜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
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>
    /// ProductionSelectionCtrl.xaml 的交互逻辑
    /// </summary>
    public partial class ProductionSelectionCtrl : UserControl
    {
        #region Property
        public static readonly DependencyProperty ProductionCodeSourceProperty;
        public static readonly DependencyProperty CurrentProductionCodeProperty;
        public static readonly DependencyProperty IsEnableChangeProductionProperty;
 
        public List<string> ProductionCodeSource
        {
            get => GetValue(ProductionCodeSourceProperty) as List<string>;
            set => SetValue(ProductionCodeSourceProperty, value);
        }
 
        public string CurrentProductionCode
        {
            get => GetValue(CurrentProductionCodeProperty).ToString();
            set => SetValue(CurrentProductionCodeProperty, value);
        }
 
        public bool IsEnableChangeProduction
        {
            get => (bool)GetValue(IsEnableChangeProductionProperty);
            set => SetValue(IsEnableChangeProductionProperty, value);
        }
        #endregion
 
        #region Event
        //public static RoutedEvent ConfirmProductionChangedEvent;
 
        //public event RoutedEventHandler Cmmd_ConfirmProducionChanged
        //{
        //    add { AddHandler(ConfirmProductionChangedEvent, value); }
        //    remove { RemoveHandler(ConfirmProductionChangedEvent, value); }
        //}
        #endregion
 
        public ProductionSelectionCtrl()
        {
            InitializeComponent();
        }
 
        static ProductionSelectionCtrl()
        {
            ProductionCodeSourceProperty = DependencyProperty.Register("ProductionCodeSource", typeof(List<string>), typeof(ProductionSelectionCtrl), new PropertyMetadata(new List<string>(), OnProductionCodeSourcePropertyChanged));
 
            CurrentProductionCodeProperty = DependencyProperty.Register("CurrentProductionCode", typeof(string), typeof(ProductionSelectionCtrl), new PropertyMetadata("", OnCurrentProductionCodePropertyChanged));
 
            IsEnableChangeProductionProperty = DependencyProperty.Register("IsEnableChangeProduction", typeof(bool), typeof(ProductionSelectionCtrl), new PropertyMetadata(true, OnIsEnableChangeProductionPropertyChanged));
 
            //ConfirmProductionChangedEvent = EventManager.RegisterRoutedEvent("ConfirmProductionChanged", RoutingStrategy.Direct, typeof(RoutedEventHandler), typeof(ProductionSelectionCtrl));
        }
 
        private static void OnIsEnableChangeProductionPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ProductionSelectionCtrl ctrl = d as ProductionSelectionCtrl;
            if (ctrl != null)
            {
                ctrl.cboPCodes.IsEnabled = ctrl.btnConfirmPCode.IsEnabled = (bool)e.NewValue;
            }
        }
 
        private static void OnCurrentProductionCodePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ProductionSelectionCtrl ctrl = d as ProductionSelectionCtrl;
            if (ctrl != null)
            {
                ctrl.cboPCodes.SelectedItem = e.NewValue.ToString();
            }
        }
 
        private static void OnProductionCodeSourcePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ProductionSelectionCtrl ctrl = d as ProductionSelectionCtrl;
            if (ctrl != null)
            {
                ctrl.cboPCodes.ItemsSource = (e.NewValue as List<string>) ?? new List<string>();
            }
        }
 
        private void btnConfirmPCode_Click(object sender, RoutedEventArgs e)
        {
            CurrentProductionCode = cboPCodes.SelectedItem.ToString();
        }
    }
}