xamarin - Detecting which item was clicked in a ListView with a DataTemplate -
i have listview simple datatemplate - image , text.
list<menuitem> items = new list<menuitem> { new menuitem ("trade","menutradeiconbig.png"), new menuitem ("profile","menuprofileiconbig.png"), }; var listview = new listview (); var viewtemplate = new datatemplate(typeof(menucell)); //menucell contains grid listview.itemtemplate = viewtemplate; listview.itemssource = items;
if listview filled strings, can this:
listview.itemtapped += (sender, e) => { menuhandler(e.item.tostring()); //my function process item clicks };
but now, when use this, response converted tostring() "myprojectname.menuitem".
how can clicked item?
i figured out:
listview.itemtapped += (sender, e) => { menuhandler((menuitem)e.item); }; public void menuhandler(menuitem item) { menuitem selected = item; //do whatever want object }
Comments
Post a Comment