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>