c# - How to select the listviewitem, where a button was clicked -
i want select listviewitem, button clicked.
here listview 2 llistviewitems
i click x-button , want delete these item out of list. how item? have these code:
private void delete_click(object sender, routedeventargs e) { var item = sender listviewitem; var obj = item.content object; list.remove(obj); }
edit: binding of listview
<listview x:name="listview"> <listview.itemtemplate> <datatemplate> <wrappanel> <textblock text="bild "/> <textblock text="{binding title}"/> <button x:name="change" content="change" margin="250,0,0,0" click="change_click"/> <button x:name="delete" content="x" margin="10,0,0,0" click="delete_click"/> </wrappanel> </datatemplate> </listview.itemtemplate> <listview.itemcontainerstyle> <style targettype="listviewitem"> <setter property="height" value="50"/> <eventsetter event="previewmouseleftbuttondown" handler="lvseriesitem_previewmouseleftbuttondown"/> </style> </listview.itemcontainerstyle> </listview>
please use instead.the control raised event not listbox button.the button datacontext of collection model object. should workd
private void delete_click(object sender, routedeventargs e) { var button= sender button; var obj =(yourmodelhere)button.datacontext; list.remove(obj); }
Comments
Post a Comment