Writing and debugging this sort of code is one of the least glamorous aspects of Windows
development.
Much to the surprise of many experienced Windows developers, the Windows Forms
toolkit didn??™t provide any features that could help you deal with these issues. Developers could
build the infrastructure they needed on their own, but most weren??™t that ambitious.
Fortunately, WPF fills in the gaps with a new commanding model. It adds two key features:
??? It delegates events to the appropriate commands.
??? It keeps the enabled state of a control synchronized with the state of the corresponding
command.
The WPF command model isn??™t quite as straightforward as you might expect. To plug into the
routed event model, it requires several separate ingredients, which you??™ll learn about in this chapter.
However, the command model is conceptually simple. Figure 10-2 shows how a commandbased
application changes the design shown in Figure 10-1. Now each action that initiates
printing (clicking the button, clicking the menu item, or pressing Ctrl+P) is mapped to the same
command. A command binding links that command to a single event handler in your code.
Figure 10-2.Mapping events to a command
CHAPTER 10 n COMMANDS 294
The WPF command system is a great tool for simplifying application design.
Pages:
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534