Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
The third component in the suite of WPF interactions is the routed command. Unlike the other two, routed commands don’t have an equivalent POCO object; they’re a completely new abstraction. (Well, new to .NET. The concept of a command has been around in other development environments for years.)
Routed commands closely model the way we think about an application when we interact with it: We issue a Copy command. We might do it from the main application menu, from the toolbar, from a context menu, or by pressing Ctrl+C, or by some other way that a clever interface designer has thought of, but whatever we actually do, what we think is “Copy”.
Here’s a typical (but ugly) example:
You can handle this situation with POCO events (programmers have been doing it forever), but it’s tedious, because every object involved needs to respond to the event and pass it on to the code that performs the operation. And, in a good interface, every object should be able to tell whether the action is actually valid at the moment and disable itself if appropriate (no point trying to copy an empty selection, for example), which means that other objects that might affect whether the command is enabled need additional events, and...did I mention tedious?