WPF and Silverlight Learning notes (15): WPF command (Commands)

Source: Internet
Author: User
Tags silverlight

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.