Pages

Sunday 28 April 2013

Difference between Events and Commands in WPF MVVM Architecture

Difference between Events and Commands in WPF MVVM Architecture

Commands are very powerful and useful feature of WPF. Cut, Copy and Paste are basic inbuilt commands in WPF. Commands and Events are related to each other to a large extent but the main concern there is that events doesn't fit well into MVVM paradigm. So we generally prefer to use commands in WPF MVVM architecture. Commands provide a lot of advantages over events. Some of them are listed below:

1. Commands in WPF allow you to move the implementation of a command handler to the buisness layer.

2. You can bind WPF command in the view (XAML) and receive the event raised. This way you do not have to use code behind which is a no-no in MVVM.

3. In events an action is tightly coupled with its source and can't be reused freely; Using commands you can easily maintain various actions in a single place and reuse them anywhere in application.

4. Commands are similar to Events except we can associate any number of UI Controls or Input Gestures to a command and bind that command to a handler that is executed when control are activated or gestures are performed.

No comments:

Post a Comment

About the Author

I have more than 10 years of experience in IT industry. Linkedin Profile

I am currently messing up with neural networks in deep learning. I am learning Python, TensorFlow and Keras.

Author: I am an author of a book on deep learning.

Quiz: I run an online quiz on machine learning and deep learning.