Button Class
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace: http://schemas.microsoft.com/winfx/2006/xaml/presentation
The Button class inherits directly from the System.Windows.Controls.Primitives.ButtonBase class.
ContentModel: The Button control is a ContentControl, which means that a button can contain content such as text, images, or panels. For more information about the content model for Button, see Content Control Content Model.
Button has a distinct ButtonBase.Click event. Button invokes the OnMouseLeftButtonDown method handler to mark an event as handled. The button Click event handles the MouseLeftButtonDown event. Hence, if you try to attach an event handler for this event, it will never occur for a button. Instead, you must use PreviewMouseLeftButtonDown to obtain this functionality.
The following example shows how to create three buttons. The example creates two buttons of different colors and a third button that is labeled Reset Colors.
<Button Name="btn1" Background="Pink" BorderBrush="Black" BorderThickness="1" Click="OnClick1"> ClickMe1 </Button> <Button Name="btn2" Background="LightBlue" BorderBrush="Black" BorderThickness="1" Click="OnClick2"> ClickMe2 </Button> <Button Name="btn3" Click="OnClick3">Reset</Button>
More Code
| How to: Create a Button That Has an Image | This example shows how to include an image on a Button. |
| How to: Create a Control That Has an Access Key and Text Wrapping | This example shows how to create a control that has an access key and supports text wrapping. The example uses a Label control to illustrate these concepts. |
System.Windows.Threading.DispatcherObject
System.Windows.DependencyObject
System.Windows.Media.Visual
System.Windows.UIElement
System.Windows.FrameworkElement
System.Windows.Controls.Control
System.Windows.Controls.ContentControl
System.Windows.Controls.Primitives.ButtonBase
System.Windows.Controls.Button
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.