diff options
| author | Mirta <mirta@twine-s.com> | 2020-12-30 16:39:52 +0200 |
|---|---|---|
| committer | Mirta <mirta@twine-s.com> | 2020-12-30 16:39:52 +0200 |
| commit | 00a491d93733d4625ad329b2ba8237f445364b3f (patch) | |
| tree | 4b24c6fa78d7648f4bb7cefafa464bb0b063fec4 /Software/Visual_Studio/Tango.SharedUI/Components/SelectedObjectCollection.cs | |
| parent | 124ad4150f80c6846fdee41dbbda9848c105f6e5 (diff) | |
| download | Tango-00a491d93733d4625ad329b2ba8237f445364b3f.tar.gz Tango-00a491d93733d4625ad329b2ba8237f445364b3f.zip | |
merge
Diffstat (limited to 'Software/Visual_Studio/Tango.SharedUI/Components/SelectedObjectCollection.cs')
| -rw-r--r-- | Software/Visual_Studio/Tango.SharedUI/Components/SelectedObjectCollection.cs | 44 |
1 files changed, 6 insertions, 38 deletions
diff --git a/Software/Visual_Studio/Tango.SharedUI/Components/SelectedObjectCollection.cs b/Software/Visual_Studio/Tango.SharedUI/Components/SelectedObjectCollection.cs index 8aa087ed3..e09bb832e 100644 --- a/Software/Visual_Studio/Tango.SharedUI/Components/SelectedObjectCollection.cs +++ b/Software/Visual_Studio/Tango.SharedUI/Components/SelectedObjectCollection.cs @@ -10,69 +10,37 @@ namespace Tango.SharedUI.Components { public class SelectedObjectCollection<T> : ObservableCollection<SelectedObject<T>> { - private Func<T, T, bool> _compareFunc; - public event EventHandler SelectionChanged; public ObservableCollection<T> Source { get; set; } public ObservableCollection<T> SynchedSource { get; set; } - public SelectedObjectCollection(ObservableCollection<T> source, ObservableCollection<T> synchedSource, Func<T, T, bool> compareFunc) + public SelectedObjectCollection(ObservableCollection<T> source, ObservableCollection<T> synchedSource) { - _compareFunc = compareFunc; - SynchedSource = synchedSource; Source = source; foreach (var item in source) { - var selectedItem = new SelectedObject<T>(item, _compareFunc == null ? synchedSource.Contains(item) : synchedSource.ToList().Exists(x => _compareFunc(x, item))); + var selectedItem = new SelectedObject<T>(item, synchedSource.Contains(item)); this.Add(selectedItem); selectedItem.IsSelectedChanged += SelectedItem_IsSelectedChanged; } } - public SelectedObjectCollection(ObservableCollection<T> source, ObservableCollection<T> synchedSource) : this(source, synchedSource, null) - { - - } - private void SelectedItem_IsSelectedChanged(object sender, EventArgs e) { SelectedObject<T> item = sender as SelectedObject<T>; - + if (item.IsSelected) { - if (_compareFunc == null) + if (!SynchedSource.Contains(item.Data)) { - if (!SynchedSource.Contains(item.Data)) - { - SynchedSource.Add(item.Data); - } - } - else - { - if (!SynchedSource.ToList().Exists(x => _compareFunc(x, item.Data))) - { - SynchedSource.Add(item.Data); - } + SynchedSource.Add(item.Data); } } else { - if (_compareFunc == null) - { - SynchedSource.Remove(item.Data); - } - else - { - foreach (var s in SynchedSource.ToList()) - { - if (_compareFunc(s, item.Data)) - { - SynchedSource.Remove(s); - } - } - } + SynchedSource.Remove(item.Data); } SelectionChanged?.Invoke(this, new EventArgs()); |
