Commands, Input and the WPF
(Page 1 of 4 )
In this fourth part of a five-part series on the input handling mechanisms available in WPF, you'll learn about command objects, input bindings, and more. It is excerpted from
Programming WPF, Second Edition, written by Chris Sells and Ian Griffiths (O'Reilly, 2007; ISBN: 0596510373). Copyright © 2007 O'Reilly Media, Inc. All rights reserved. Used with permission from the publisher. Available from booksellers or direct from O'Reilly Media.
Command Objects
A command object identifies a particular command. It does not know how to handle a command—as we’ve seen, that’s the job of a command binding. Command objects are typically made available through static properties, such as ApplicationCommands.Properties.
There are several places from which you can get hold of a command object. Some controls define commands. For example, theScrollBarcontrol defines one for each of its actions, and makes these available in static fields, such asLineUpCommandandPageDownCommand. However, most commands are not unique to a particular control. Some correspond to application-level actions such as “new file” or “open.” Others represent actions that could be implemented by several different controls. For example,TextBoxandRichTextBoxcan both handle clipboard operations.
WPF provides a set of classes that define standard commands. These classes are shown in Table 4-4. This means you don’t need to create your own command objects to represent the most common operations. Moreover, built-in controls understand many of these commands.
Table 4-4. Standard command classes
| Class | Command types |
| ApplicationCommands | Commands common to almost all applications. Includes clipboard commands, undo and redo, and document-level operations (open, close, print, etc.). |
| ComponentCommands | Operations for moving through information, such as scroll up and down, move to end, and text selection. |
| EditingCommands | Text editing commands such as bold, italic, center, and justify. |
| MediaCommands | Media-playing operations such as transport (play, pause, etc.), volume control, and track selection. |
| NavigationCommands | Browser-like navigation commands such as Back, Forward, and Refresh. |
Although the standard commands cover a lot of the common features found in many applications, applications usually have functionality of their own not addressed by the standard commands. You can use the command system for application-specific actions by defining custom commands.
Next: Defining commands >>
More .NET Articles
More By O'Reilly Media
|
This article is excerpted from Programming WPF, Second Edition, written by Chris Sells and Ian Griffiths (O'Reilly, 2007; ISBN: 0596510373). Check it out today at your favorite bookstore. Buy this book now.
|
|