Adding programatically a command to a listbox in WPF

Posted by ajtp on Stack Overflow See other posts from Stack Overflow or by ajtp
Published on 2010-03-30T15:03:00Z Indexed on 2010/03/31 1:43 UTC
Read the original article Hit count: 547

Filed under:
|
|

In my WPF application there is a listbox with items. The listbox is populated via a xmldataprovider from XAML and then binding it to Itemssource property of the listbox.

Well, from XAML, I bind a comand to the listbox by doing:

                      <ListBox.CommandBindings>
                          <CommandBinding 
                              Command="{x:Static local:mainApp.MyCmd}" 
                              CanExecute="CanExecute"
                              Executed ="Executed" />
                      </ListBox.CommandBindings>

but I don't know how to programatically bind a command to each listboxitem. How to do it?

Thanks in advance.

© Stack Overflow or respective owner

Related posts about command

Related posts about listboxitem