Chapter 10. Commands

 

This chapter covers:

  • Approaches to command handling
  • The command pattern
  • System commands
  • Custom commands
  • Us gesturing at our application and our application gesturing back

In the last chapter, we created a simple application shell, but it doesn’t do anything. In this chapter, we’ll look at how WPF approaches the interaction between the presentation and business logic, and implement some custom business logic as well. Unlike the calculator, the implementation of the wiki in this chapter will show how WPF applications should be hooked together—no cheating by putting business logic in the UI.

Fortunately, WPF provides a lot of tools to accomplish a properly separated business logic layer—although, like Windows Forms, you can easily slide into allowing business logic in the UI. Even though commands are nothing new to Windows development, WPF marks the official introduction of commands into the .NET world (and about time too). This isn’t to say we can’t all create our own command models in .NET; but, without a common model to work around, this can lead to some pretty horrible-looking code when trying to integrate many third-party components, all taking similar but slightly varying approaches to the problem.

10.1. A brief history of commands

10.2. The WPF approach

10.3. Using the built-in system commands

10.4. Handling commands

10.5. Command routing

10.6. A cleaner custom command implementation

10.7. Summary