aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.SharedUI/Components/SelectedObjectCollection.cs
diff options
context:
space:
mode:
authorRoy <roy.mail.net@gmail.com>2018-02-12 09:40:08 +0200
committerRoy <roy.mail.net@gmail.com>2018-02-12 09:40:08 +0200
commit2bef1ef7fb1d5cd57e2af3f47a648e512cfcd4f2 (patch)
tree53ff9fc86a9e56d5cd54a53ecddf85aa4656dd6a /Software/Visual_Studio/Tango.SharedUI/Components/SelectedObjectCollection.cs
parenta84ca3e4bee123600c08f8897eca5be83b3ffcf8 (diff)
downloadTango-2bef1ef7fb1d5cd57e2af3f47a648e512cfcd4f2.tar.gz
Tango-2bef1ef7fb1d5cd57e2af3f47a648e512cfcd4f2.zip
Implemented motor group.
Diffstat (limited to 'Software/Visual_Studio/Tango.SharedUI/Components/SelectedObjectCollection.cs')
-rw-r--r--Software/Visual_Studio/Tango.SharedUI/Components/SelectedObjectCollection.cs46
1 files changed, 46 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.SharedUI/Components/SelectedObjectCollection.cs b/Software/Visual_Studio/Tango.SharedUI/Components/SelectedObjectCollection.cs
new file mode 100644
index 000000000..c9a1a6293
--- /dev/null
+++ b/Software/Visual_Studio/Tango.SharedUI/Components/SelectedObjectCollection.cs
@@ -0,0 +1,46 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Collections.Specialized;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.SharedUI.Components
+{
+ public class SelectedObjectCollection<T> : ObservableCollection<SelectedObject<T>>
+ {
+ public ObservableCollection<T> Source { get; set; }
+ public ObservableCollection<T> SynchedSource { get; set; }
+
+ public SelectedObjectCollection(ObservableCollection<T> source, ObservableCollection<T> synchedSource)
+ {
+ SynchedSource = synchedSource;
+ Source = source;
+
+ foreach (var item in source)
+ {
+ var selectedItem = new SelectedObject<T>(item, synchedSource.Contains(item));
+ this.Add(selectedItem);
+ selectedItem.IsSelectedChanged += SelectedItem_IsSelectedChanged;
+ }
+ }
+
+ private void SelectedItem_IsSelectedChanged(object sender, EventArgs e)
+ {
+ SelectedObject<T> item = sender as SelectedObject<T>;
+
+ if (item.IsSelected)
+ {
+ if (!SynchedSource.Contains(item.Data))
+ {
+ SynchedSource.Add(item.Data);
+ }
+ }
+ else
+ {
+ SynchedSource.Remove(item.Data);
+ }
+ }
+ }
+}