ButtonBase ButtonBase ButtonBase Class

Represents the base class for all button controls, such as Button, RepeatButton, and HyperlinkButton.

Syntax

Declaration

public class ButtonBasepublic class ButtonBasePublic Class ButtonBase

Inheritance Hierarchy

Inherited Members

, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
Tag
Tag
Tag
, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Remarks

ButtonBase derived classes

ButtonBase is the parent class for several immediately derived controls that refine specific button behaviors for UI interaction:

Examples

The following example demonstrates handling the Click event and setting the IsEnabled property of a Button, which inherits from ButtonBase.

<StackPanel>   
    <Button Content="Submit" 
            Click="submitButtonClick"/>
    <TextBlock x:Name="textBlock1"/>
</StackPanel>
void submitButtonClick(object sender, RoutedEventArgs e)
{
    textBlock1.Text = "You clicked the Submit button.";
}
Private Sub submitButtonClick(ByVal sender As Object, ByVal e As RoutedEventArgs)
    textBlock1.Text = "You clicked the Submit button."
End Sub

Properties summary

Gets or sets a value that indicates when the Click event occurs, in terms of device behavior.

Identifies the ClickMode dependency property.

Gets or sets the command to invoke when this button is pressed.

Gets or sets the parameter to pass to the Command property.

Identifier for the CommandParameter dependency property.

Identifier for the Command dependency property.

Gets a value that indicates whether a device pointer is located over this button control.

Identifies the IsPointerOver dependency property.

Gets a value that indicates whether a ButtonBase is currently in a pressed state.

Identifies the IsPressed dependency property.

Events summary

Occurs when a button control is clicked.

Properties

  • ClickMode
    ClickMode
    ClickMode
    ClickMode

    Gets or sets a value that indicates when the Click event occurs, in terms of device behavior.

    public ClickMode ClickMode { get; set; }public ClickMode ClickMode { get; set; }Public ReadWrite Property ClickMode As ClickMode
    <button ClickMode="clickModeMemberName"/>
    
    

    Property Value

    Remarks

    Examples

    The following example shows three buttons that respond to clicks in three different ways based on their ClickMode property value.

    • Hover - When the mouse pointer hovers over the first button, the foreground color of the button changes.
    • Press - When the left mouse button is pressed while over the second button, the foreground color of the button changes.
    • Release - When the mouse button is pressed and released while over the third button, the button resets the foreground color of the other two buttons to their original color.
    <StackPanel x:Name="LayoutRoot" Margin="10">
      <Button x:Name="btn1" Content="Hover to Click"
              Click="OnClick1" ClickMode="Hover"
              Margin="5" Width="150"
              HorizontalAlignment="Left"
              Foreground="Green"/>
      <TextBlock x:Name="text1" Margin="5,8,0,0" />
      
      <Button x:Name="btn2" Content="Press to Click"
              Click="OnClick2" ClickMode="Press"
              Margin="5,5,5,5" Width="150" 
              HorizontalAlignment="Left" 
              Foreground="Blue"/>
      <TextBlock x:Name="text2" Margin="5,8,0,0" />
      
      <Button x:Name="btn3" Content="Reset"
              Click="OnClick3" ClickMode="Release"
              Margin="5,5,5,5" Width="150"
              HorizontalAlignment="Left"/>
      <TextBlock x:Name="text3" Margin="5,8,0,0" />
    </StackPanel>
    
    void OnClick1(object sender, RoutedEventArgs e)
    {
        btn1.Foreground = new SolidColorBrush(Windows.UI.Colors.Blue);
        text1.Text = "Click event occurs on Hover.";
        text2.Text = "";
        text3.Text = "";
    }
    
    void OnClick2(object sender, RoutedEventArgs e)
    {
        btn2.Foreground = new SolidColorBrush(Windows.UI.Colors.Green);
        text1.Text = "";
        text2.Text = "Click event occurs on Press.";
        text3.Text = "";
    }
    
    void OnClick3(object sender, RoutedEventArgs e)
    {
        btn1.Foreground = new SolidColorBrush(Windows.UI.Colors.Green);
        btn2.Foreground = new SolidColorBrush(Windows.UI.Colors.Blue);
        text1.Text = "";
        text2.Text = "";
        text3.Text = "Click event occurs on Release.";
    }
    
    Private Sub OnClick1(ByVal sender As Object, ByVal e As RoutedEventArgs)
        btn1.Foreground = New SolidColorBrush(Windows.UI.Colors.Blue)
        text1.Text = "Click event handled on Hover."
        text2.Text = ""
        text3.Text = ""
    End Sub
    
    Private Sub OnClick2(ByVal sender As Object, ByVal e As RoutedEventArgs)
        btn2.Foreground = New SolidColorBrush(Windows.UI.Colors.Green)
        text1.Text = ""
        text2.Text = "Click event handled on Press."
        text3.Text = ""
    End Sub
    
    Private Sub OnClick3(ByVal sender As Object, ByVal e As RoutedEventArgs)
        btn1.Foreground = New SolidColorBrush(Windows.UI.Colors.Green)
        btn2.Foreground = New SolidColorBrush(Windows.UI.Colors.Blue)
        text1.Text = ""
        text2.Text = ""
        text3.Text = "Click event handled on Release."
    End Sub
    
  • ClickModeProperty
    ClickModeProperty
    ClickModeProperty
    ClickModeProperty

    Identifies the ClickMode dependency property.

    public static DependencyProperty ClickModeProperty { get; }public static DependencyProperty ClickModeProperty { get; }Public Static ReadOnly Property ClickModeProperty As DependencyProperty

    Property Value

  • Command
    Command
    Command
    Command

    Gets or sets the command to invoke when this button is pressed.

    public ICommand Command { get; set; }public ICommand Command { get; set; }Public ReadWrite Property Command As ICommand
    <button Command="commandReference"/>
    
    

    Property Value

    Remarks

    The ICommand interface comes from a different source depending on whether the data source is implemented in C++ or for Microsoft .NET. C++ implements ICommand. Microsoft .NET implements System.Windows.Input.ICommand. Both interfaces have the same template. Which interface you call from your app code is analogous: use ICommand for C++ code and System.Windows.Input.ICommand for Microsoft .NET code.

  • CommandParameter
    CommandParameter
    CommandParameter
    CommandParameter

    Gets or sets the parameter to pass to the Command property.

    public object CommandParameter { get; set; }public object CommandParameter { get; set; }Public ReadWrite Property CommandParameter As object
    <button>
      <button.CommandParameter>
        object
      </button.CommandParameter>
    </button>
    

    Property Value

    • object
      object
      object

      The parameter to pass to the Command property. The default is null.

  • CommandParameterProperty
    CommandParameterProperty
    CommandParameterProperty
    CommandParameterProperty

    Identifier for the CommandParameter dependency property.

    public static DependencyProperty CommandParameterProperty { get; }public static DependencyProperty CommandParameterProperty { get; }Public Static ReadOnly Property CommandParameterProperty As DependencyProperty

    Property Value

  • CommandProperty
    CommandProperty
    CommandProperty
    CommandProperty

    Identifier for the Command dependency property.

    public static DependencyProperty CommandProperty { get; }public static DependencyProperty CommandProperty { get; }Public Static ReadOnly Property CommandProperty As DependencyProperty

    Property Value

  • IsPointerOver
    IsPointerOver
    IsPointerOver
    IsPointerOver

    Gets a value that indicates whether a device pointer is located over this button control.

    public bool IsPointerOver { get; }public bool IsPointerOver { get; }Public ReadOnly Property IsPointerOver As bool

    Property Value

    • bool
      bool
      bool

      True if a pointer is over the button control; otherwise false. The default is false.

  • IsPointerOverProperty
    IsPointerOverProperty
    IsPointerOverProperty
    IsPointerOverProperty

    Identifies the IsPointerOver dependency property.

    public static DependencyProperty IsPointerOverProperty { get; }public static DependencyProperty IsPointerOverProperty { get; }Public Static ReadOnly Property IsPointerOverProperty As DependencyProperty

    Property Value

  • IsPressed
    IsPressed
    IsPressed
    IsPressed

    Gets a value that indicates whether a ButtonBase is currently in a pressed state.

    public bool IsPressed { get; }public bool IsPressed { get; }Public ReadOnly Property IsPressed As bool

    Property Value

    • bool
      bool
      bool

      True if the ButtonBase is in a pressed state; otherwise false. The default is false.

  • IsPressedProperty
    IsPressedProperty
    IsPressedProperty
    IsPressedProperty

    Identifies the IsPressed dependency property.

    public static DependencyProperty IsPressedProperty { get; }public static DependencyProperty IsPressedProperty { get; }Public Static ReadOnly Property IsPressedProperty As DependencyProperty

    Property Value

Events

  • Click
    Click
    Click
    Click

    Occurs when a button control is clicked.

    public event RoutedEventHandler Clickpublic event RoutedEventHandler ClickPublic Event Click
    <button Click="eventhandler"/>
    

    Remarks

    Examples

    The following example demonstrates handling the Click event and setting the IsEnabled property of a Button, which inherits from ButtonBase.

    <StackPanel>   
        <Button Content="Submit" 
                Click="submitButtonClick"/>
        <TextBlock x:Name="textBlock1"/>
    </StackPanel>
    
    void submitButtonClick(object sender, RoutedEventArgs e)
    {
        textBlock1.Text = "You clicked the Submit button.";
    }
    
    Private Sub submitButtonClick(ByVal sender As Object, ByVal e As RoutedEventArgs)
        textBlock1.Text = "You clicked the Submit button."
    End Sub
    

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Attributes

Windows.Foundation.Metadata.ComposableAttribute
Windows.Foundation.Metadata.ContractVersionAttribute
Windows.Foundation.Metadata.WebHostHiddenAttribute
Windows.Foundation.Metadata.MarshalingBehaviorAttribute
Windows.Foundation.Metadata.StaticAttribute
Windows.Foundation.Metadata.ThreadingAttribute

Details

Assembly

Windows.UI.Xaml.Controls.Primitives.dll