Binding Commands to Events?
-
Hi, What's a good method to bind Commands to Events? In my WPF app, there are events that I'd like to capture and process by my ViewModel but I'm not sure how. Things like losing focus, mouseover, mousemove, etc. Since I'm trying to adhere to the MVVM pattern, I'm wondering if there's a XAML solution for that. Thanks!
-
Hi, What's a good method to bind Commands to Events? In my WPF app, there are events that I'd like to capture and process by my ViewModel but I'm not sure how. Things like losing focus, mouseover, mousemove, etc. Since I'm trying to adhere to the MVVM pattern, I'm wondering if there's a XAML solution for that. Thanks!
These events are, strictly speaking, view only events, so why would you want them to be handled in the VM? There's no rule that says you can't have code behind the view, so if you need to do things, you can do it there. What are you trying to do that goes beyond the V/VM separation?
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
-
These events are, strictly speaking, view only events, so why would you want them to be handled in the VM? There's no rule that says you can't have code behind the view, so if you need to do things, you can do it there. What are you trying to do that goes beyond the V/VM separation?
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
Hi Pete, Those events were just examples. It can be any type of event that I might need to handle. In our application we can change XAML files dynamically, so we're trying to avoid solutions that involve code-behind files. Thanks!
-
Hi, What's a good method to bind Commands to Events? In my WPF app, there are events that I'd like to capture and process by my ViewModel but I'm not sure how. Things like losing focus, mouseover, mousemove, etc. Since I'm trying to adhere to the MVVM pattern, I'm wondering if there's a XAML solution for that. Thanks!
I haven't tried it yet, but this answer looks promising. http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0cb73e76-b7dd-4a47-af27-cd05da2f305e[^]
-
I haven't tried it yet, but this answer looks promising. http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0cb73e76-b7dd-4a47-af27-cd05da2f305e[^]
-
I don't know your actual requirement but ICommand can be helpful in such situations. It makes your view cleaner. May I get the exact scenario for the problem? :)
Niladri Biswas
modified on Thursday, June 4, 2009 10:32 AM
-
I don't know your actual requirement but ICommand can be helpful in such situations. It makes your view cleaner. May I get the exact scenario for the problem? :)
Niladri Biswas
modified on Thursday, June 4, 2009 10:32 AM
I suspect you meant to raise this against the OP, not me. He won't be notified of posts against my account, so could you reply to him instead.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
-
Hi, What's a good method to bind Commands to Events? In my WPF app, there are events that I'd like to capture and process by my ViewModel but I'm not sure how. Things like losing focus, mouseover, mousemove, etc. Since I'm trying to adhere to the MVVM pattern, I'm wondering if there's a XAML solution for that. Thanks!
I don't know your actual requirement but ICommand can be helpful in such situations. It makes your view cleaner. May I get the exact scenario for the problem? :)
Niladri Biswas