c# - WPF: Raise an Event when Item is added in ListView -


i working on wpf , using listview, , need fire event when item added it. have tried this:

var dependencypropertydescriptor = dependencypropertydescriptor.fromproperty(itemscontrol.itemssourceproperty, typeof(listview));         if (dependencypropertydescriptor != null)         {                dependencypropertydescriptor.addvaluechanged(this, itemssourcepropertychangedcallback);         } 

.....

 private void itemssourcepropertychangedcallback(object sender, eventargs e)     {          raiseitemssourcepropertychangedevent();     } 

but seems working when entire collection changed, have read post: event-fired-when-item-is-added-to-listview, best answer applies listbox only. tried change code listview wasnt able that.

i hope can me. thank in advance.

note works wpf listview!

after research have found answer question , it's easy:

public mycontrol() {     initializecomponent();     ((inotifycollectionchanged)listview.items).collectionchanged +=  listview_collectionchanged; }  private void listview_collectionchanged(object sender, notifycollectionchangedeventargs e)      {     if (e.action == notifycollectionchangedaction.add)     {       // scroll new item view          listview.scrollintoview(e.newitems[0]);     } } 

actually, notifycollectionchangedaction enum allows program inform change such as: add, move, replace, remove , reset.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -