From 070db71577b05f72e7531d0e530a4ef5bd1d128a Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Thu, 7 May 2020 14:44:45 +0300 Subject: Users & Roles ! --- .../Components/SelectedObjectCollection.cs | 44 +++++++++++++++++++--- 1 file changed, 38 insertions(+), 6 deletions(-) (limited to 'Software/Visual_Studio/Tango.SharedUI/Components/SelectedObjectCollection.cs') diff --git a/Software/Visual_Studio/Tango.SharedUI/Components/SelectedObjectCollection.cs b/Software/Visual_Studio/Tango.SharedUI/Components/SelectedObjectCollection.cs index e09bb832e..8aa087ed3 100644 --- a/Software/Visual_Studio/Tango.SharedUI/Components/SelectedObjectCollection.cs +++ b/Software/Visual_Studio/Tango.SharedUI/Components/SelectedObjectCollection.cs @@ -10,37 +10,69 @@ namespace Tango.SharedUI.Components { public class SelectedObjectCollection : ObservableCollection> { + private Func _compareFunc; + public event EventHandler SelectionChanged; public ObservableCollection Source { get; set; } public ObservableCollection SynchedSource { get; set; } - public SelectedObjectCollection(ObservableCollection source, ObservableCollection synchedSource) + public SelectedObjectCollection(ObservableCollection source, ObservableCollection synchedSource, Func compareFunc) { + _compareFunc = compareFunc; + SynchedSource = synchedSource; Source = source; foreach (var item in source) { - var selectedItem = new SelectedObject(item, synchedSource.Contains(item)); + var selectedItem = new SelectedObject(item, _compareFunc == null ? synchedSource.Contains(item) : synchedSource.ToList().Exists(x => _compareFunc(x, item))); this.Add(selectedItem); selectedItem.IsSelectedChanged += SelectedItem_IsSelectedChanged; } } + public SelectedObjectCollection(ObservableCollection source, ObservableCollection synchedSource) : this(source, synchedSource, null) + { + + } + private void SelectedItem_IsSelectedChanged(object sender, EventArgs e) { SelectedObject item = sender as SelectedObject; - + if (item.IsSelected) { - if (!SynchedSource.Contains(item.Data)) + if (_compareFunc == null) { - SynchedSource.Add(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); + } } } else { - SynchedSource.Remove(item.Data); + if (_compareFunc == null) + { + SynchedSource.Remove(item.Data); + } + else + { + foreach (var s in SynchedSource.ToList()) + { + if (_compareFunc(s, item.Data)) + { + SynchedSource.Remove(s); + } + } + } } SelectionChanged?.Invoke(this, new EventArgs()); -- cgit v1.3.1