Using routed commands

WPF provides two (similar) implementations for the ICommand interface. Commands are invoked (by default) by command sources, implementing the ICommandSource interface. These two interfaces comprise the basic abstraction WPF recognizes as far as commands are concerned. In this recipe, we'll examine these interfaces, their out-of-the-box implementations, and how they are typically used.

Getting ready

Make sure Visual Studio is up and running.

How to do it...

We'll create a simple image viewer that provides its functionality via WPF routed commands:

  1. Create a new WPF application named CH07.RoutedCommands.
  2. Open MainWindow.xaml. Add the following to the existing Grid:
    <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition ...

Get Windows Presentation Foundation 4.5 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.