开发者

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

开发者 https://www.devze.com 2023-03-30 23:15 出处:网络
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 b

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 co开发者_StackOverflow社区mmand 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消