c# - ListBox MenuItem Data template binding -
i have following code:
<listbox itemssource="{binding itemslist}"> <listbox.itemtemplate> <datatemplate> <stackpanel orientation="vertical"> <textblock text="{binding}"/> </stackpanel> </datatemplate> </listbox.itemtemplate> <listbox.contextmenu > <contextmenu itemssource="{binding menuitemdatalist}"> <datatemplate datatype="{x:type model:menuitemdata}" > <menuitem header="{binding name}" /> </datatemplate> </contextmenu> </listbox.contextmenu> </listbox> </grid>
it throws exception message when right click in order show pop-up menu:
items collection must empty before using itemssource.
itemslist
, menuitemdatalist
diferent collections.
i think need put datatemplate inside contextmenu.itemtemplate
<listbox.contextmenu > <contextmenu itemssource="{binding menuitemdatalist}"> <contextmenu.itemtemplate> <datatemplate datatype="{x:type model:menuitemdata}"> <menuitem header="{binding name}" /> </datatemplate> </contextmenu.itemtemplate> </contextmenu> </listbox.contextmenu>
Comments
Post a Comment