aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.SharedUI/Components/SelectedObjectCollection.cs
diff options
context:
space:
mode:
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);
+ }
+ }
+ }
+}