1 //------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //------------------------------------------------------------
5 namespace System.Activities.Presentation.Toolbox
7 using System.Collections;
8 using System.Collections.Generic;
9 using System.Collections.ObjectModel;
10 using System.Collections.Specialized;
11 using System.ComponentModel;
12 using System.Diagnostics.CodeAnalysis;
15 [SuppressMessage(FxCop.Category.Design, "CA1039:ListsAreStronglyTyped",
16 Justification = "The nongeneric IList implementation is required for XAML support. It is implmented explicitly.")]
17 [SuppressMessage(FxCop.Category.Naming, "CA1710:IdentifiersShouldHaveCorrectSuffix",
18 Justification = "The collection implemenation is required for XAML support.")]
19 public sealed class ToolboxCategory : INotifyPropertyChanged, IList
22 ObservableCollection<ToolboxItemWrapper> tools = new ObservableCollection<ToolboxItemWrapper>();
24 public ToolboxCategory()
29 public ToolboxCategory(string name)
31 this.categoryName = name;
32 this.tools.CollectionChanged += this.OnToolCollectionChanged;
35 public string CategoryName
37 get { return this.categoryName; }
40 this.categoryName = value;
41 this.OnPropertyChanged("CategoryName");
45 public ToolboxItemWrapper this[int index]
47 get { return this.tools[index]; }
50 [Fx.Tag.KnownXamlExternal]
51 public ICollection<ToolboxItemWrapper> Tools
53 get { return this.tools; }
56 public void Add(ToolboxItemWrapper tool)
60 throw FxTrace.Exception.ArgumentNull("tool");
65 public bool Remove(ToolboxItemWrapper tool)
69 throw FxTrace.Exception.ArgumentNull("tool");
71 return this.tools.Remove(tool);
74 internal void HandleToolCollectionNotification(NotifyCollectionChangedEventHandler listener, bool register)
78 throw FxTrace.Exception.ArgumentNull("listener");
82 this.tools.CollectionChanged += listener;
86 this.tools.CollectionChanged -= listener;
90 void OnToolCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
94 case NotifyCollectionChangedAction.Add:
95 foreach (var tool in e.NewItems)
99 throw FxTrace.Exception.ArgumentNull("tool");
104 this.OnPropertyChanged("Tools");
107 void OnPropertyChanged(string propertyName)
109 if (null != this.PropertyChanged)
111 this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
115 public event PropertyChangedEventHandler PropertyChanged;
117 #region IList Members
119 int IList.Add(object value)
121 this.Add((ToolboxItemWrapper)value);
122 return this.tools.IndexOf((ToolboxItemWrapper)value);
130 bool IList.Contains(object value)
134 throw FxTrace.Exception.ArgumentNull("value");
136 return this.tools.Contains((ToolboxItemWrapper)value);
139 int IList.IndexOf(object value)
143 throw FxTrace.Exception.ArgumentNull("value");
145 return this.tools.IndexOf((ToolboxItemWrapper)value);
148 void IList.Insert(int index, object value)
152 throw FxTrace.Exception.ArgumentNull("value");
154 this.tools.Insert(index, (ToolboxItemWrapper)value);
157 bool IList.IsFixedSize
159 get { return ((IList)this.tools).IsFixedSize; }
162 bool IList.IsReadOnly
164 get { return ((IList)this.tools).IsReadOnly; }
167 void IList.Remove(object value)
169 this.Remove((ToolboxItemWrapper)value);
172 void IList.RemoveAt(int index)
174 this.tools.RemoveAt(index);
177 object IList.this[int index]
181 return this.tools[index];
187 throw FxTrace.Exception.ArgumentNull("value");
189 this.tools[index] = (ToolboxItemWrapper)value;
195 #region ICollection Members
197 void ICollection.CopyTo(Array array, int index)
201 throw FxTrace.Exception.ArgumentNull("array");
203 ((ICollection)this.tools).CopyTo(array, index);
206 int ICollection.Count
208 get { return this.tools.Count; }
211 bool ICollection.IsSynchronized
213 get { return ((ICollection)this.tools).IsSynchronized; }
216 object ICollection.SyncRoot
218 get { return ((ICollection)this.tools).SyncRoot; }
223 #region IEnumerable Members
225 IEnumerator IEnumerable.GetEnumerator()
227 return this.tools.GetEnumerator();