button click using command ^ events, briefly

As illustrated in other blog posts (like http://bigblog.tanbin.com/2013/06/routed-events-learning-notes.html), a button click can be connected to (via xaml) a regular instance method in the xaml class (code behind), provided the method is an event handler. In this implementation, we are using a CLR event, not really routed event.

This simple design draws criticism such as tight coupling etc. There’s an alternative. Using commands, we can refactor to meet the same requirement. [[wpf succinctly]] has a simple example of this refactor.

Another book says — “In WPF and Silverlight, there are two ways to respond to user interaction: with events and with commands. Most controls will support both of these methods of interaction, but it seems more common for events to be exposed.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s