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

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -