This documentation is archived and is not being maintained.

Button Class

Represents a Windows button control, which reacts to the ButtonBase.Click event.

Namespace:  System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)

Public Class Button _
	Inherits ButtonBase
Dim instance As Button

The Button class inherits directly from the System.Windows.Controls.Primitives.ButtonBase class.

Content Model: Button is a ContentControl. Its content property is Content. For more information on the content model for Button, see Controls Content Model Overview.

Handle the ButtonBase.Click event to respond when the user clicks a Button.

The OnMouseLeftButtonDown method marks the MouseLeftButtonDown event as handled. To respond to the MouseLeftButtonDown event, attach an event handler to the PreviewMouseLeftButtonDown event, or call AddHandler(RoutedEvent, Delegate, Boolean) with handledEventsToo set to true.

Dependency properties for this control might be set by the control’s default style. If a property is set by a default style, the property might change from its default value when the control appears in the application. The default style is determined by which desktop theme is used when the application is running. For more information, see Themes.

The following example shows three buttons that respond to clicks in three different ways.

  • Hover: the first button changes colors when the user hovers with the mouse over the button.

  • Press: the second button requires that the mouse be pressed while the mouse pointer is over the button.

  • Release: the third does not reset the background color of the buttons until the mouse is pressed and released on the button.

<Button Name="btn1" Background="Pink" 
        BorderBrush="Black" BorderThickness="1" 
        Click="OnClick1" ClickMode="Hover">

<Button Name="btn2" Background="LightBlue" 
        BorderBrush="Black" BorderThickness="1" 
        Click="OnClick2" ClickMode="Press">

<Button Name="btn3" 
        Click="OnClick3" ClickMode="Release">
Private Sub OnClick1(ByVal sender As Object, ByVal e As RoutedEventArgs)
    btn1.Background = Brushes.LightBlue
End Sub 

Private Sub OnClick2(ByVal sender As Object, ByVal e As RoutedEventArgs)
    btn2.Background = Brushes.Pink
End Sub 

Private Sub OnClick3(ByVal sender As Object, ByVal e As RoutedEventArgs)
    btn1.Background = Brushes.Pink
    btn2.Background = Brushes.LightBlue
End Sub

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.


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0