views:

28

answers:

2

Hello everybody,

I have got a question about event and bound command.

What happens if I bound a command to my button and also handle the click event in my code behind ?

I mean, I have already tried and everything is ok but I was wondering whether this affects the efficiency or something else ? Is it a good practice ?

In my case the code behind is just to close a window after it has executed a command.

thank you everybody

A: 

This is definitely not a best practice, since they are two different ways of achieving the same outcome. What you may want to do investigate as a solution, is passing a callback as the parameter (or part of the parameter object) of your command and have the command call the method/callback.

If you must, you can also specify, with a flag, whether the callback should be called before of after the command's code block completes.

Hugo
ok thanks to everybody for the answers
Gerrrard
A: 

It's deterministic, but I only think it's "good practice" if:

  • Your command is providing some business logic AND
  • The click event is being handled to do something purely view-related, such as begin a storyboard.

You could always trigger the view response from the viewmodel instead if you wanted (in my example you could use a datastatebehavior)

Rob Fonseca-Ensor