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

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -