Hi,
I'm using XamDataGrid with MVVM,
I implemented a Context Menu as the below post
XamDataGrid ContextMenu Handler in MVVM
I also implemented a Dependency Property to bind SelectedItems in my ViewModel, where I subscribe to the event SelectedItemsChanged of the XamDataGrid to update the bind collection.
The problem, is that "drp.DataPresenter.ActiveRecord = drp.Record;" in RecordActivationAction doesn't trigger SelectedItemsChange, actually the active record is not mark as selected. The context menu items are bind to commands, those commands use selected items as source.
I can't just add the record to the selected items, because the user might press CTRL, SHIFT or nothing when they mouse click, changing which records will be in the selected items after.
Any suggestions,
Thanks,
Dominik
Hello Dominik,
I have been looking into your description and this is the expected behavior since the SelectedItems.Records Collection has any items only if there are selected records other form the ActiveRecord. In other words if only one record is selected, thus activated, there is no need for the Selecteditems.Records collection and since only the ActiveRecord can be used, only the RecrodActivating/Activated events are fired. I can suggest you handle them in order to fill in the missing logic in your implementation.
Please let me know if you require any further clarification on the matter.
Hi Petar,
Thanks, for you awnser, I think I understand your suggestion, I actually found what I the behavior I wanted. In RecordActivationAction If the clicked record is not in SelectedItems.Records of the XamDataGrid instance, I clear the SelectedItems.Records and I add the newly click record to the SelectedItems.Records, if the clicked row is already in SelectedItems.Records I do nothing. In either case I set the clicked record as the ActiveRecord
The behavior correspond to what I expected, If I right click an unselected row, that row only get selected and the context menu is relative to that row only, if I right click a selected row, the context menu is relative to the selected rows. I thought that pressing CTRL or SHIFT would change that behavior, but after some testing that behavior just seems more natural.