Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/DynamicDataDisplay/Common/Auxiliary/ObservableCollectionHelper.cs @ 13808

Last change on this file since 13808 was 12503, checked in by aballeit, 9 years ago

#2283 added GUI and charts; fixed MCTS

File size: 900 bytes
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Collections.ObjectModel;
6using System.Collections.Specialized;
7
8namespace Microsoft.Research.DynamicDataDisplay.Common.Auxiliary
9{
10  internal static class ObservableCollectionHelper
11  {
12    public static void ApplyChanges<T>(this ObservableCollection<T> collection, NotifyCollectionChangedEventArgs args)
13    {
14      if (args.NewItems != null)
15      {
16        int startingIndex = args.NewStartingIndex;
17        var newItems = args.NewItems;
18
19        for (int i = 0; i < newItems.Count; i++)
20        {
21          T addedItem = (T)newItems[i];
22          collection.Insert(startingIndex + i, addedItem);
23        }
24      }
25      if (args.OldItems != null)
26      {
27        for (int i = 0; i < args.OldItems.Count; i++)
28        {
29          T removedItem = (T)args.OldItems[i];
30          collection.Remove(removedItem);
31        }
32      }
33    }
34  }
35}
Note: See TracBrowser for help on using the repository browser.