-
Notifications
You must be signed in to change notification settings - Fork 0
/
BatchProgress.xaml.cs
131 lines (108 loc) · 3.44 KB
/
BatchProgress.xaml.cs
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
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
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.Shapes;
namespace ColorMatch3D
{
/// <summary>
/// Interaction logic for BatchProgress.xaml
/// </summary>
public partial class BatchProgress : Window
{
public FullyObservableCollection<ProgressItem> ProgressStrings
{
get { return progressStrings; }
}
public FullyObservableCollection<ProgressItem> progressStrings = new FullyObservableCollection<ProgressItem>();
public BatchProgress()
{
InitializeComponent();
this.DataContext = this;
}
public void AddOrUpdateProgressItem(int id, string message="...")
{
bool found = false;
foreach (ProgressItem progressString in progressStrings)
{
if(progressString.id == id)
{
Dispatcher.Invoke(() => {
progressStrings[progressStrings.IndexOf(progressString)].ProgressText = message;
});
//progressString.progressText = message;
found = true;
break;
}
}
if (!found)
{
Dispatcher.Invoke(()=> {
progressStrings.Add(new ProgressItem(message, id));
});
}
}
public void RemoveProgressItem(int id, string message="...")
{
foreach (ProgressItem progressString in progressStrings)
{
if(progressString.id == id)
{
progressStrings.Remove(progressString);
break;
}
}
}
}
public class ProgressItem : INotifyPropertyChanged
{
public int id;
public string ProgressText
{
get { return _progressText; }
set
{
_progressText = value;
RaisePropertyChanged("ProgressText");
}
}
private string _progressText;
public int Id
{
get { return id; }
}
public ProgressItem(string progressTextA = "", int currentIndexA = 0)
{
ProgressText = progressTextA;
id = currentIndexA;
}
public static implicit operator string(ProgressItem d) => d.ProgressText;
public static implicit operator ProgressItem(string b) => new ProgressItem(b);
public override string ToString()
{
return ProgressText;
}
/// PropertyChanged event handler
public event PropertyChangedEventHandler PropertyChanged;
/// Property changed Notification
public void RaisePropertyChanged(string propertyName)
{
// take a copy to prevent thread issues
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}
}