I assign a List<int> to the ItemsSource of ListBox, and the form inherits the INotifyCollectionChanged interface. However, when I delete the value in the List<int>, the CollectionChanged event will be null. How can I implement this interface?
my code example:
...
private List<int> myin = new List<int>();
public event NotifyCollectionChangedEventHandler CollectionChanged;
//Remove a number.
private void Button_Click(object sender, RoutedEventArgs e)
{
myin.Remove(34);
if (CollectionChanged != null) CollectionChanged(this,
new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove,myin));
}
//initalize List<int> and binding to ListBox.ItemsSource.
private void Window_Loaded(object sender, RoutedEventArgs e)
{
for(int i = 0; i < 100; i++)
{
myin.Add(i);
}
lis.ItemsSource = myin;
}
