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
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.
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)
精彩评论