- 追加された行はこの色です。
- 削除された行はこの色です。
&tag(ObservableCollection);
*目次 [#obceca1a]
#contents
*参考情報 [#k9315b6f]
*Tips [#v413c8d4]
**AddRangeがない [#y8cc45d0]
-[[ObservableCollection.AddRange : The Official Microsoft Silverlight Site:http://forums.silverlight.net/forums/p/35357/106025.aspx]]…自分で拡張を書くしかないのか。
-次のような拡張を作り、使用する箇所でImportする。
#pre{{
public static class CollectionExtender
{
public static void AddRange<T>(this ObservableCollection<T> collection, ICollection<T> addCollection)
{
foreach (var addItem in addCollection)
{
collection.Add(addItem);
}
}
}
}}
-ObservableCollectionにAddRangeできるようになる。
#pre{{
ObservableCollection<Person> persons = new ObservableCollection<Person>();
List<Person> otherPersons = new List<Person>() {new Person(), new Person() ...};
persons.AddRange(otherPersons);
}}