I have a XamDataGrid
which is bound to an observable collection. As the XamDataGrid
is editable, records can be added/edited/deleted. I have implemented CollectionChanged
& PropertyChanged
events.
The CollectionChanged
event contains the following code:
if (e.Action == NotifyCollectionChangedAction.Remove || e.Action == NotifyCollectionChangedAction.Add)
{
if (e.OldItems != null)
{
// Detach the event handler from current instance;
foreach (BusinessTelephone oldItem in e.OldItems)
{
if (oldItem is INotifyPropertyChanged)
{
(oldItem as INotifyPropertyChanged).PropertyChanged -= new PropertyChangedEventHandler(PhoneDetails_PropertyChanged);
}
}
}
if (e.NewItems != null)
{
// Attach the event handler to the new instance;
foreach (BusinessTelephone newItem in e.NewItems)
{
if (newItem is INotifyPropertyChanged)
{
(newItem as INotifyPropertyChanged).PropertyChanged += new PropertyChangedEventHandler(PhoneDetails_PropertyChanged);
}
}
}
}
All of this is working fine.
I have a strange problem which is given below.
When I add a record in the grid and delete it from the grid, I am removing the item from the collection by looping through the collection
Ex: PhoneDetailsCollection.Remove(item);
Now, when I add another record, the CollectionChanged
event is not getting fired.
Did I miss something here? Any help is highly appreciated...