wpf - How do i get the value of selected item from list box in windows phone application using c# -
i'm trying value of selected item list box , display message using messagebox.show(). xaml code list box
<listbox x:name="lbtodolist" grid.row="1" width="350" margin="100,0,0,0"> <listbox.background> <lineargradientbrush endpoint="0.5,1" startpoint="0.5,0"> <gradientstop color="#ff060000" offset="0"/> </lineargradientbrush> </listbox.background> <listbox.itemtemplate> <datatemplate> <stackpanel orientation="horizontal"> <textblock x:name="listbox" grid.row="1" text="{binding salutationname}" /> </stackpanel> </datatemplate> </listbox.itemtemplate> </listbox>
and c# code data binding is
list<userdata> info = jsonconvert.deserializeobject<list<userdata>>(e.result); list<userdata> items = new list<userdata>(); lbtodolist.items.clear(); foreach (userdata item in info) { items.add(new userdata() { salutationname = item.salutationname }); } this.lbtodolist.itemssource = items;
and display selected item
string text = lbtodolist.selecteditem.tostring(); messagebox.show(text);
but problem instead of display selected item,it displaying projectname.classname
a simple fix override tostring of userdata give expecting.
public class userdata { ... public override string tostring() { return this.somevalue; } }
Comments
Post a Comment