开发者

Triggering a command in the view model based on an action in the view

开发者 https://www.devze.com 2023-04-03 12:03 出处:网络
I am working with the Infragistics XamDatagrid.When an event takes place in the view (new record updated), I would like to call a method in the view model.I can\'t just listen to the CollectionChanged

I am working with the Infragistics XamDatagrid. When an event takes place in the view (new record updated), I would like to call a method in the view model. I can't just listen to the CollectionChanged event of the source in the VM because that event gets triggered once the user begins editing the new row in the grid. The RecordUpdating event gets called when the user finished the edits.

What I am doing now is accessing the DataContext directly and calling the method. The problem is that there is nowhere I can find to attach a Command to 开发者_如何学编程the gird that would tigger on the event I am interested, nothing like the Command of a Button.

Generally, what is the best way to call into a VM from a view when there is no Command parameter I can set in the view?


Code-behind glue is fine in most cases, but if you find yourself gluing the same type of thing repeatedly, you can look into Attached Behaviors. Here's one old-school approach the introduces the concepts, but doesn't use the new Behavior class: http://www.codeproject.com/KB/WPF/AttachedBehaviors.aspx

Here is an example using the new Behavior class, including a demonstration of how it integrates with Blend: http://geekswithblogs.net/lbugnion/archive/2009/04/05/using-a-behavior-to-magnify-your-wpf-applications.aspx

0

精彩评论

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

关注公众号