MVVM Light EventToCommand 和 Silverlight DataForm - 我需要 EventArgs 和自定义 CommandParameter。可能的?
我有一个绑定到 RoleViewModel 对象集合的 DataForm
。我使用 MVVMLight 的 EventToCommand
行为绑定到 DataForm
的 EditEnding
事件来在角色被编辑时通知我的 ViewModel。
现在,...用户编辑角色,可以单击“确定”、“取消”,也可以直接离开。此信息保存在 DataFormEditEndedEventArgs
的 DataFormEditAction
属性中(OK 为 DataFormEditAction.Commit
,其他为 DataFormEditAction.Cancel
代码>)。
问题是我必须选择是选择 PassEventArgsToCommand
,使命令的签名 RelayCommand
还是绑定的 CurrentItem
将 DataForm
绑定到行为的 CommandParameter
,从而形成签名 RelayCommand
。我将需要两者。
我需要 EventArgs
来了解用户是否取消了编辑,并且如果他们没有取消编辑,我需要新角色将其保存回数据库。
这里有人有什么聪明的建议吗?我想我可以亲自动手并使用两个参数创建第二种行为,但如果有更优雅的解决方案,我宁愿不这样做。
任何帮助将不胜感激。
提前致谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的视图模型保存了 newrole 到数据表单的可绑定值,那么您可以 PassEventArgsToCommand,并且可以在保存/更新/取消之前操作数据。
这就是我们解决类似场景的方法。
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.