I've been searching for some information on binding WPF events to commands defined in a ViewModel.
I know there are many frameworks that can do it for me, but I don't want to use any of them, but implement something from scratch to see how it's working.
I've found this article: http://blog.functionalfun.net/2008/09/hooking-up-commands-to-events-in-wpf.html
and in general it's very good. However, I've got two questions:
I'd like to have a command with a parameter and bind the parameter to a property in XAML (like
CommandParameter={Binding ...}). How to extend the article to handle this ?In my understanding in this implementation to use, let's say, a
MouseDoubleClickevent in two different UI Elements, I need to define two different properties and attach them to each of the types I want to extend. Isn't there a smarter way (i.e. defining an Attached Property once and then use it in all the elements)?
Attached Propertycontaining theICommandparameters to use. Regarding q2: if I understand your needs, you can use just oneAttached Propertyshared among multiple commands, but I guess it's clearer and better to define anAttached PropertyforeachICommand. - trix