I am using ListViewCollection class with my dataGrid. The underlying collection is an observable collection.
Whenever i call Move methods in the collection ( which is in ViewModel), the CurrentChanged Event doesnt fire.
However when UI calls the same method on it ( i can see it in the call stack), the event does fire.
this.EmailTemplates = new ListCollectionView(templateVmList);
this.EmailTemplates.CurrentChanging += (o, e) => EmailTemplates_CurrentChanging(o, e);
this.EmailTemplates.CurrentChanged += (o, e) => { this.SelectedEmailTemplate = (EmailTemplateViewModel)this.EmailTemplates.CurrentItem; };
if (this.EmailTemplates.Count > 0)
{
if (!this.EmailTemplates.MoveCurrentToFirst())
throw new ArgumentException("Element not found in collection");
}
What should i do in code to make sure the events fire no matter who is changing the collection.
Try using
CollectionViewSource.GetDefaultViewinstead of creating a newListCollectionView.This test code worked fine for me