diff --git a/TuneUp/TuneUpWindowViewModel.cs b/TuneUp/TuneUpWindowViewModel.cs index a61a769..e5d4b7a 100644 --- a/TuneUp/TuneUpWindowViewModel.cs +++ b/TuneUp/TuneUpWindowViewModel.cs @@ -74,6 +74,7 @@ public class TuneUpWindowViewModel : NotificationObject, IDisposable private Dictionary groupDictionary = new Dictionary(); // Maps AnnotationModel GUIDs to a list of associated ProfiledNodeViewModel instances. private Dictionary> groupModelDictionary = new Dictionary>(); + private Dictionary, CollectionViewSource> collectionMapping = new Dictionary, CollectionViewSource>(); private HomeWorkspaceModel CurrentWorkspace { @@ -320,6 +321,12 @@ internal void ResetProfiledNodes() ProfiledNodesPreviousRun = ProfiledNodesPreviousRun ?? new ObservableCollection(); ProfiledNodesNotExecuted = ProfiledNodesNotExecuted ?? new ObservableCollection(); + collectionMapping = new Dictionary, CollectionViewSource> { + { ProfiledNodesLatestRun, ProfiledNodesCollectionLatestRun }, + {ProfiledNodesPreviousRun, ProfiledNodesCollectionPreviousRun }, + {ProfiledNodesNotExecuted, ProfiledNodesCollectionNotExecuted } + }; + nodeDictionary = new Dictionary(); groupDictionary = new Dictionary(); groupModelDictionary = new Dictionary>(); @@ -546,7 +553,7 @@ private void CalculateGroupNodes() groupDictionary[pGroup.NodeGUID] = pGroup; groupModelDictionary[pNode.GroupGUID].Add(pGroup); - System.Windows.Application.Current.Dispatcher.Invoke(() => + ProfiledNodesCollectionLatestRun.Dispatcher.Invoke(() => { ProfiledNodesNotExecuted.Add(pGroup); }); @@ -612,7 +619,7 @@ private void CreateGroupNodesForCollection(ObservableCollection + GetCollectionViewSource(collection).Dispatcher.Invoke(() => { collection.Add(timeNode); collection.Add(pGroup); @@ -1030,6 +1037,14 @@ private void UpdateTableVisibility() RaisePropertyChanged(nameof(NotExecutedTableVisibility)); } + /// + /// Returns the corresponding CollectionViewSource for the given ObservableCollection of ProfiledNodeViewModel. + /// + internal CollectionViewSource GetCollectionViewSource(ObservableCollection collection) + { + return collectionMapping.TryGetValue(collection, out var collectionViewSource) ? collectionViewSource : null; + } + /// /// Resets group-related properties of the node and unregisters it from the group model dictionary. /// @@ -1267,7 +1282,7 @@ private void SortCollectionViewForProfiledNodesCollection(ObservableCollection

private void MoveNodeToCollection(ProfiledNodeViewModel profiledNode, ObservableCollection targetCollection) { - System.Windows.Application.Current.Dispatcher.Invoke(() => + GetCollectionViewSource(targetCollection).Dispatcher.Invoke(() => { var collections = new[] { @@ -1292,7 +1307,7 @@ private void RemoveNodeFromStateCollection(ProfiledNodeViewModel pNode, Profiled { var collection = GetObservableCollectionFromState(state); - System.Windows.Application.Current.Dispatcher.Invoke(() => + GetCollectionViewSource(collection).Dispatcher.Invoke(() => { collection?.Remove(pNode); });