Commands in WPF: Part II

Introduction

In Part I of this article series we have seen the basics of using Commands. In this article we will explore more on that.

Concepts of Command System

There are five concepts related to Command System:

  1. Command Object

    - An object identifying a particular Command, such as Copy or Paste.
     
  2. Input Binding

    - An association between a particular input (e.g. CTRL+C) and a Command (e.g. Copy)
     
  3. Command Source

    - The object that invoked the Command, such as a Button or Input Binding.
     
  4. Command Target

    - The UI element that will be asked to execute the Command.
     
  5. Command Binding

    - A declaration that a particular UI element knows how to handle a particular Command.

Let's modify our Application a bit. As follows:

image1.gif

image2.gif

As you see above we have a Button that will display the properties when it is clicked.

Remember that in Windows ALT+ENTER is the Command that will execute the Command for displaying Properties.

Let's have implemented the concepts that we have just discussed about.

image3.gif

As you see from the above Code Display, we have a CommandBinding object that takes the argument as a Command.

On Executed event handler we have just displayed a MessageBox.

Let's run the application.

image4.gif

When we click on Properties Button the following Message Box is displayed.

image5.gif

So we can have our own display if we want to display our custom Properties Window in this event handler.

Hope this article helps learning the CommandBinding concept.