c# - Get selected item from a bound listbox -
i have listbox of users , want selected item it.i used selecteditem returns 0 . listbox xaml code:
<listbox name="_imagelist" margin="10,10,10,0" issynchronizedwithcurrentitem="true" scrollviewer.horizontalscrollbarvisibility="visible" verticalalignment="top" height="250" borderthickness="0" selectionchanged="list_clicked"> <!--<listbox.itemcontainerstyle> <style targettype="{x:type listboxitem}" basedon="{staticresource {x:type listboxitem}}"> <eventsetter event="mouseleftbuttondown" handler="listboxitem_mouseleftbuttondown"/> </style> </listbox.itemcontainerstyle>--> <listbox.itemtemplate> <datatemplate datatype="enfant"> <border cornerradius="30"> <grid> <grid.rowdefinitions> <rowdefinition/> <rowdefinition/> </grid.rowdefinitions> <button grid.row="0" width="50" height="80" click="btn_click"> <button.template> <controltemplate> <image x:name="image" source="{binding avatar}"/> </controltemplate> </button.template> </button> <textblock grid.row="1" x:name="nom" text="{binding prenom}" verticalalignment="center"/> </grid> </border> </datatemplate> </listbox.itemtemplate> </listbox>
and code behind:
private void btn_click(object sender, routedeventargs e) { if (onkidclick != null) { kid = new enfant(); onkidclick(this, new routedeventargs()); var item = _imagelist.selecteditem; } }
you handle selected item in selectionchanged="list_clicked"
method need in method.
Comments
Post a Comment