INotifyCollectionChanged를 구현하는 SortedDictionary 위에 래퍼 클래스를 만들어야합니다.
public class SyncSortedDictionary<T1,T2> : INotifyCollectionChanged, IDictionary<T1,T2>
{
#region Fields
private readonly SortedDictionary<T1,T2> _items;
#endregion
#region Events
public event NotifyCollectionChangedEventHandler CollectionChanged;
#endregion
#region Notify
private void OnCollectionChanged(NotifyCollectionChangedAction action, object item, int index)
{
OnCollectionChanged(new NotifyCollectionChangedEventArgs(action, item, index));
}
private void OnCollectionChanged(NotifyCollectionChangedAction action, object item, int index, int oldIndex)
{
OnCollectionChanged(new NotifyCollectionChangedEventArgs(action, item, index, oldIndex));
}
private void OnCollectionChanged(NotifyCollectionChangedAction action, object oldItem, object newItem, int index)
{
OnCollectionChanged(new NotifyCollectionChangedEventArgs(action, newItem, oldItem, index));
}
private void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
{
var collectionChanged = CollectionChanged;
if (collectionChanged == null)
return;
collectionChanged(this, e);
}
#endregion
#region Public Methods
public void Add(KeyValuePair<T1, T2> item)
{
int index = _items.Count;
_items.Add(item.Key, item.Value);
OnCollectionChanged(NotifyCollectionChangedAction.Add, item, index);
}
#endregion
}
감사하지만, 어떻게 MainWindow를에 목록 상자 컨트롤이를 듣거나 결합 않습니다
간단한 예 (물론 당신이 사전의 모든 메소드를 구현해야)? 미안 해요 wpf에 새로 왔어. – quacksquared