领胜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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
using Bro.Common.Model;
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;
using T047.Process;
 
namespace Bro.UI.RunRelated
{
    /// <summary>
    /// CoordinateDisplayCtrl.xaml 的交互逻辑
    /// </summary>
    public partial class CoordinateDisplayCtrl : UserControl
    {
        public CoordinateDisplayCtrl()
        {
            InitializeComponent();
 
            lvResults.ItemsSource = PointsSource;
            //lvResults.PreviewMouseWheel += (sender, e) =>
            //  {
            //      var eventArg = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta);
            //      eventArg.RoutedEvent = UIElement.MouseWheelEvent;
            //      eventArg.Source = sender;
            //      lvResults.RaiseEvent(eventArg);
            //  };
        }
 
        public static readonly DependencyProperty PointsSourceProperty;
 
        public IEnumerable<ComplexPoint> PointsSource
        {
            get => GetValue(PointsSourceProperty) as IEnumerable<ComplexPoint>;
            set => SetValue(PointsSourceProperty, value);
        }
 
        static CoordinateDisplayCtrl()
        {
            List<ComplexPoint> list = new List<ComplexPoint>() { };
 
            //for (int i = 0; i < 10; i++)
            //{
            //    ComplexPoint point = new ComplexPoint() { ImagePoint = new DirectionAidPoint(i * 0.123f, i), PlatPoint = new DirectionAidPoint(i, i) };
 
            //    if (i < 6)
            //    {
            //        point.IsCurrent = false;
            //    }
            //    else if (i == 6)
            //    {
            //        point.IsCurrent = true;
            //    }
 
            //    list.Add(point);
            //}
 
            PointsSourceProperty = DependencyProperty.Register("PointsSource", typeof(IEnumerable<ComplexPoint>), typeof(CoordinateDisplayCtrl), new PropertyMetadata(list, OnPointsSourcePropertyChanged));
        }
 
        private static void OnPointsSourcePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            CoordinateDisplayCtrl ctrl = d as CoordinateDisplayCtrl;
            if (ctrl != null)
            {
                var points = e.NewValue as IEnumerable<ComplexPoint>;
                ctrl.lvResults.ItemsSource = points;
 
                ctrl.ShowCurrentPoint();
                //foreach (ComplexPoint p in points)
                //{
                //    p.PropertyChanged -= ctrl.P_PropertyChanged;
                //    p.PropertyChanged += ctrl.P_PropertyChanged;
                //}
            }
        }
 
        private void P_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if ((e.PropertyName == "IsCurrent") && (((ComplexPoint)sender).IsCurrent ?? false))
            {
                ShowCurrentPoint();
            }
        }
 
        private void ShowCurrentPoint()
        {
            //int totalNum = lvResults.Items.Count;
            //if (totalNum <= 0)
            //    return;
 
            //int rowDisplayNum = (int)(lvResults.ActualHeight / 25.0 / 2.0);
 
            //ComplexPoint point = lvResults.Items[totalNum - 1] as ComplexPoint;
            //for (int i = totalNum - 1; i >= 0; i--)
            //{
            //    if (((ComplexPoint)lvResults.Items[i]).IsCurrent ?? false)
            //    {
            //        do
            //        {
            //            if ((i + rowDisplayNum) < totalNum)
            //            {
            //                point = (ComplexPoint)lvResults.Items[i + rowDisplayNum];
            //            }
 
            //            rowDisplayNum--;
            //        } while (rowDisplayNum >= 0 && point == null);
            //        break;
            //    }
            //}
 
            //lvResults.Dispatcher.Invoke(() => lvResults.ScrollIntoView(point));
 
            if (lvResults.Items.Count <= 0)
                return;
 
            lvResults.Dispatcher.Invoke(() => lvResults.ScrollIntoView(lvResults.Items[lvResults.Items.Count - 1]));
        }
 
        private void lvResults_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            ShowCurrentPoint();
        }
    }
}