c# - How to use ListBox.Items as Itemsource of a List<String> -
i have listbox. have list in code behind. want items listbox source of list.
i tried way:
<listbox x:name="mylist" .../>
list<string> feed = new list<string>(); //to source var feed = mylist.items.cast<string>().tolist(); but it's throwing exception: system.invalidcastexception
what do?
you getting error because list isn't made of strings! try string representation instead.
list<string> feed = mylist.items.cast<object>() .select(o => o.tostring()).tolist();
Comments
Post a Comment