ARTICLE

Commands in WPF: Part II

Posted by Diptimaya Patra Articles | WPF March 09, 2010
In Part I of this article series we have seen the basics of using Commands. In this article we will explore more on that.
Reader Level:
Download Files:
 

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.

Login to add your contents and source code to this article
post comment
     

Hi,

After your first part I was wondering that there might be quite nice and comprehensive article addressing commands in WPF in a short way. But now I got disappointed as the second part also does not introduce anything. Just few paragraphs loosely coupled with the subject.

Why introduce another article which does not introduce any value to the existing materials? Why to make noise on the portals? I would like to read a good tutorial or programming technique presentation, maybe some specific problem discussion. I belive that the others would, too. Publishing such "articles" decreases value of the portal itself and discourages people to read.

Posted by rolandz May 04, 2010
COMMENT USING
PREMIUM SPONSORS
DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and add new content to existing PDF documents from within your applications.
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.