"Programming WPF" Translation 3rd Chapter 3. Inline controls

Source: Internet
Author: User

WPF provides a series of inline controls. Most of these conform to standard Windows control types that you are already familiar with. Note that none of the controls are wrapped outside the old Win32 control. Although they look like copies of them, they are all inherently WPF controls. This means that they provide complete support for the features described in WPF in this book, including styling, independent resolution, data binding, compositing, and full integration to support the graphical capabilities of WPF.

3.3.1 Button

A button is a control that a user can tap. The results of the clicks are up to the developer of the program, but the common expectation depends on the type of button. For example, clicking on a checkbox or RadioButton to indicate a selection does not normally have any immediate effect to reflect that choice. By contrast, clicking on a normal button usually has an immediate effect.

The use of buttons is straightforward. Example 3-11 shows the markup for a BUTTON element.

Example 3-11

<Button Click="ButtonClicked">Button</Button>

The content of the element (in this case, button text) is used for the caption of the button. The handle to the click event is specified explicitly by a property. This indicates that the XAML's background code must contain a method that specifies the name explicitly in the label, as shown in example 3-12 (we can also subordinate event handles by giving the button a x:name and using the normal C # event handle syntax.) )

Example 3-12

private void ButtonClicked(object sender, RoutedEventArgs e) {
    MessageBox.Show("Button was clicked");
}

Optionally, a button general's properties can be set, in which case the specified command will be invoked when the button is clicked. Example 3-13 shows a button to invoke the Standard applicationcommands.copy command.

Example 3-13

<Button Command="Copy">Copy</Button>

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.