Hi,
I'm currently playing around with a MVVM/Commands and ControlTemplates. What I'm trying to do is quite simple. I want to have a list of e.g. Persons, where the user can trigger an action on each of them. But the event/commandhandler needs to be executed not on the person object e.g. because I want remove it from the list with a button.
So what I did so far was to create a VM that exposes a list of PersonVM's and each of the holds my person object. Then I created a CustomControl with a controltemplate that includes an ItemsControl that displayes my persons.
All the data is displayed nicely, and no problem at all.
Then I tried to add the part that allows the user to remove a person from the list. So I added a button to the datatemplate. Still not a problem.
Next step was to expose a command that is triggered by the button.
The first approach was to use Josh Smiths RelayCommand. So I added one of those to the PersonViewModel and bound it to the button. It works, but the problem is that I need to raise an event (after the command is executed) that the parent vm has to handle. Imho that is not nice, as with more and more commands the code seems messy to me.
So I reworked everything to use RoutedCommand, and tried to add a CommandBinding on a higher level in the control hierarchy. But this is not possible as the ControlTemplate doesn't allow me to call a method on the viewmodel.
So I'm wondering what is the correct approach for that problem? Somehow I believe that I'm on the wrong track, but I don't see where.
tia Martin