I have a MainView that contains a DataGrid that displays a collection of ViewModels. I used this http://www.thesilvermethod.com/default.aspx?Id=VMCollectionWrapperSynchronizeaModelcollectionwithaViewModelcollection example to implement the ViewModel Collection.
Within the DataGrid's rows is a button to delete each row. The problem is that when clicked it accesses the delete command from the ViewModel that is within the ViewModel collection. How do I then get this ViewModel to delete itself from within itself?
Options that I have considered but have been unsussesfull include;
- Reference the VMcollection in each of the ViewModels that it contains
- Reference the model collection in the viewModel that the VMcollection is wrapping
- Refference the parent ViewModel in each ViewModel of the VMcollection
I am completely at a lost on what to do and no reseach has shown an answer. Is it possible to redirect the datacontext of each delete button to the parent ViewModel and delete the child ViewModels from there? if so how would I do this and pass in which child ViewModel (grid line) I need to delete?