This project is read-only.

Event handling

Aug 6, 2010 at 9:20 PM
Edited Aug 6, 2010 at 9:32 PM
Hi, I'm trying to use MEFedMVVM and find its features nice, but still have some questions. One of them is about event handling. So, there are few options to do it: 1. using code-behind: Then, from code-behind call handler on VM. It's the simplest way. But with MEFedMVVM we additionally need to cast DataContext to VM type. 2. using IContextAware and find named visual element in the view and then attach handlers in VM: Not very good because of its bound on elements name. 3. using ACB: Sorry, I don't like it because there is no possibility to deal with event args. And I think using reflection for such purpose is not very fast solution. 4. using attached properties or Behaviors(from interactivity ns): Requires too much code for simple event handling. So, maybe I've missed something? Are there any other ways? How do you deal with event handling? I'm just trying to find the right way for myself... Thanks.
Aug 6, 2010 at 9:33 PM

Hi muenchausen,

I use MEFedMVVM with Cinch and have absolut no problems with event handling. You can use EventToCommandTrigger from cinch library and binding to command on viewmodel with event arguments and, if you want, with additional command parameters. It's very easy to use and all Blendable

Aug 6, 2010 at 10:02 PM
Hi dimax, Thanks for the answer. I've just took a look at EventToCommandTrigger. The code looks nice. But there is one thing I worry about - it definitely uses Reflection. I just don't want to sacrifice a lot in execution speed for the nice looked code... No, really, I understand that I will not feel any difference in speed if I will use it for one event, but if it will more than one...I'm not sure.
Aug 6, 2010 at 10:45 PM

Is your problem that event intensiv?

If so, I think every "looks nice" solution is not for nothing so simple. LINQ looks nice, but costs performance. I didn't have event performance problems yet, it's just the normal user interaction software. But with MEF performance at start time (not so big problem) and with WPF graphic performance itself (CAD like software), thats what my two problems are. Full screen resizing, drawing is to slow for me.

But I'm not a WPF or MVVM guru, maybe I'm missing something too.

Aug 9, 2010 at 9:56 AM
hi Muenchausen, I also suggest using the EventToCommandTrigger. Its true it uses reflection but hey so does WPF Binding and many other things.... I do have an implementation that is a "bit faster" then standard reflection (since it uses DynamicMethod instead of reflection) you can see it over here having said that Cinch is an awesome framework... I suggest you go with that since it has loads of goodies out of the box....