wpf - In ListBox cannot add Items after ItemSource is set to null -
i have assigned itemssource property of first listbox 'listbox1' itemssource of listbox namely 'listbox2' . if set listbox2's itemssource null, unable add items further listbox1's itemssource.
below xaml snippet,
<listbox verticalalignment="top" horizontalalignment="center" width="150" margin="0 25 0 0" x:name="listbox1" itemssource="{binding coll,mode=twoway}"> <listbox.itemtemplate> <datatemplate> <textblock text="{binding _name}"/> </datatemplate> </listbox.itemtemplate> </listbox> <listbox verticalalignment="top" horizontalalignment="center" width="150" margin="0 25 0 0" x:name="listbox2" itemssource="{binding path=itemssource,elementname=listbox1,mode=twoway}"> <listbox.itemtemplate> <datatemplate> <textblock text="{binding _name}"/> </datatemplate> </listbox.itemtemplate> </listbox>
in code behind, set itemsource of listbox2 null on button click below,
listbox2.setcurrentvalue(listbox.itemssourceproperty, null);
once done, tried add items listbox1's "coll" collection, throws nre "coll" null.
any suggestions plz.
regards, dinesh kumar p
the two-way binding on listbox2.itemssource
sets listbox1.itemssource
null
when listbox2.itemssource
set null
. subsequently, two-way binding on listbox1.itemssource
sets coll
null
.
don't make itemssource
bindings two-way. not necessary, , collection changes still notified.
<listbox x:name="listbox1" itemssource="{binding coll}" ... > ... </listbox> <listbox x:name="listbox2" itemssource="{binding path=itemssource, elementname=listbox1}" ... > ... </listbox>
it's not clear going achieve, may better bind listbox2.itemssource
directly coll
property.
Comments
Post a Comment