Command Routing and event routing in WPF are two very beginner headaches concepts, and for command routing, it can be understood that system (WPF) defines a series of actions that can be used directly in an application. For example, you can simply do this by defining a series of menus to copy, cut, and paste the text boxes in the form:
1: <Grid>
2: <Grid.RowDefinitions>
3: <RowDefinition Height="23" />
4: <RowDefinition />
5: </Grid.RowDefinitions>
6: <Menu Grid.Row="0" Grid.Column="0">
7: <MenuItem Header="Edit">
8: <MenuItem x:Name="menuCopy" Header="Copy"
9: Command="ApplicationCommands.Copy" />
10: <MenuItem x:Name="menuCut" Header="Cut"
11: Command="ApplicationCommands.Cut" />
12: <MenuItem x:Name="menuPaste" Header="Paste"
13: Command="ApplicationCommands.Paste" />
14: </MenuItem>
15: </Menu>
16: <TextBox Grid.Row="1" Grid.Column="0" x:Name="mainText"
17: TextWrapping="Wrap" AcceptsReturn="True" />
18: </Grid>
The routing command model in WPF can be divided into four main concepts: command, command source, command target, and command binding:
The command is the action to perform. In this case, the command is Applicationcommands.copy, cut, Paste
The command source is the object that invokes the command. In this example, the command source is three MenuItem controls
The command target is the object on which the command is executed. In this case, the command target is maintext this textbox text box
A command binding is an object that maps command logic to a command. In this example, the command is bound to a system-defined copy, cut, paste operation for a text box,
The relationship between the four is shown in the following illustration: