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:
Create a new WPF application named
CH07.RoutedCommands
.Open
MainWindow.xaml
. Add the following to the existingGrid
:<Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition /> </Grid.RowDefinitions> <ToolBar FontSize="14"> </ToolBar> <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" Grid.Row="1"> <Image Source="{Binding...