|
using System.Collections.ObjectModel;
using System.Linq;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Collections.Generic;
namespace ClearStyle.ViewModel
{
/// <summary>
/// An ObservableCollection which exposes a Reset method, which raises a CollectionChanged
/// eventy of type 'NotifyCollectionChangedAction.Reset'.
/// </summary>
public class ObservableCollectionEx<T> : ObservableCollection<T>
{
public ObservableCollectionEx()
{
}
public ObservableCollectionEx(IEnumerable<T> list)
: base(list)
{
}
public void Reset()
{
OnCollectionChanged(new NotifyCollectionChangedEventArgs(
NotifyCollectionChangedAction.Reset));
}
#region property changed relay
protected override void InsertItem(int index, T item)
{
var propertyChangedItem = item as INotifyPropertyChanged;
if (propertyChangedItem != null)
{
propertyChangedItem.PropertyChanged += Item_PropertyChanged;
}
base.InsertItem(index, item);
}
protected override void RemoveItem(int index)
{
T item = this[index];
var propertyChangedItem = item as INotifyPropertyChanged;
if (propertyChangedItem != null)
{
propertyChangedItem.PropertyChanged -= Item_PropertyChanged;
}
base.RemoveItem(index);
}
private void Item_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
RelayedPropertyChanged(sender, e);
}
public event PropertyChangedEventHandler RelayedPropertyChanged = delegate { };
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.