Have you implemented INotifyCollectionChanged
? you need this for notifications of actions like adding or removing items from a collection.
here is a simple implementation for queue:
public class ObservableQueue<T> : INotifyCollectionChanged, IEnumerable<T>
{
public event NotifyCollectionChangedEventHandler CollectionChanged;
private readonly Queue<T> queue = new Queue<T>();
public void Enqueue(T item)
{
queue.Enqueue(item);
if (CollectionChanged != null)
CollectionChanged(this,
new NotifyCollectionChangedEventArgs(
NotifyCollectionChangedAction.Add, item));
}
public T Dequeue()
{
var item = queue.Dequeue();
if (CollectionChanged != null)
CollectionChanged(this,
new NotifyCollectionChangedEventArgs(
NotifyCollectionChangedAction.Remove, item));
return item;
}
public IEnumerator<T> GetEnumerator()
{
return queue.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…