Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/DynamicDataDisplay/Common/NotifyingPanels/NotifyingUIElementCollection.cs @ 13757

Last change on this file since 13757 was 12503, checked in by aballeit, 10 years ago

#2283 added GUI and charts; fixed MCTS

File size: 2.2 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Windows.Controls;
6using System.Windows;
7using System.Collections.Specialized;
8using System.Collections.ObjectModel;
9
10namespace Microsoft.Research.DynamicDataDisplay.Common
11{
12  internal sealed class NotifyingUIElementCollection : UIElementCollection, INotifyCollectionChanged
13  {
14    public NotifyingUIElementCollection(UIElement visualParent, FrameworkElement logicalParent)
15      : base(visualParent, logicalParent)
16    {
17      collection.CollectionChanged += OnCollectionChanged;
18    }
19
20    private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
21    {
22      CollectionChanged.Raise(this, e);
23    }
24
25    #region Overrides
26
27    private readonly D3UIElementCollection collection = new D3UIElementCollection();
28
29    public override int Add(UIElement element)
30    {
31      collection.Add(element);
32      return base.Add(element);
33    }
34
35    public override void Clear()
36    {
37      collection.Clear();
38      base.Clear();
39    }
40
41    public override void Insert(int index, UIElement element)
42    {
43      collection.Insert(index, element);
44      base.Insert(index, element);
45    }
46
47    public override void Remove(UIElement element)
48    {
49      collection.Remove(element);
50      base.Remove(element);
51    }
52
53    public override void RemoveAt(int index)
54    {
55      collection.RemoveAt(index);
56      base.RemoveAt(index);
57    }
58
59    public override void RemoveRange(int index, int count)
60    {
61      for (int i = index; i < index + count; i++)
62      {
63        collection.RemoveAt(i);
64      }
65      base.RemoveRange(index, count);
66    }
67
68    public override UIElement this[int index]
69    {
70      get
71      {
72        return base[index];
73      }
74      set
75      {
76        collection[index] = value;
77        base[index] = value;
78      }
79    }
80
81    public override int Count
82    {
83      get
84      {
85        return collection.Count;
86      }
87    }
88
89    #endregion
90
91    #region INotifyCollectionChanged Members
92
93    public event NotifyCollectionChangedEventHandler CollectionChanged;
94
95    #endregion
96  }
97
98  internal sealed class D3UIElementCollection : D3Collection<UIElement>
99  {
100    protected override void OnItemAdding(UIElement item)
101    {
102      if (item == null)
103        throw new ArgumentNullException("item");
104    }
105  }
106}
Note: See TracBrowser for help on using the repository browser.