MVVM Light EventToCommand and Silverlight DataForm - I need the EventArgs and a custom CommandParameter. Possible?

StackOverflow https://stackoverflow.com/questions/7214235

Question

I have a DataForm bound to a collection of RoleViewModel objects. I'm using MVVMLight's EventToCommand behaviour bound to the EditEnding event of the DataForm to inform my ViewModel when a Role has been edited.

Now,... the user edits a role and can either click 'OK', 'Cancel' or they can simply navigate away. This information is held in the DataFormEditAction property in the DataFormEditEndedEventArgs (OK being DataFormEditAction.Commit and the others being DataFormEditAction.Cancel).

The problem is that I have to choose whether I select PassEventArgsToCommand, making the signature of the command RelayCommand<DataFormEditEndedEventArgs> or I bind the CurrentItem of the DataForm to the CommandParameter of the behaviour, making the signature RelayCommand<RoleViewModel>. I'm going to need both.

I need the EventArgs to know whether the user has cancelled the edit or not and I need the new Role to save it back to the database if they didn't cancel it.

Does anyone have any clever suggestions here? I guess I could get my hands dirty and create a second behaviour with two parameters but I'd rather not if there's a more elegant solution.

Any help would be greatly appreciated.

Thanks in advance.

Was it helpful?

Solution

If your viewmodel holds a bindable value of the newrole to the dataform, then you can PassEventArgsToCommand, and you can manipulate data before saving/updating/cancelling.

This is how we have solved a similar scenario.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top