ButtonBase ButtonBase ButtonBase Class

Definition

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

public class ButtonBasepublic class ButtonBasePublic Class ButtonBase
Inheritance
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Inherited Members

Inherited properties

Inherited events

Inherited methods

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

Constructors

ButtonBase() ButtonBase() ButtonBase() ButtonBase()

Provides base class initialization behavior for ButtonBase derived classes.

protected ButtonBase()protected New()Protected Sub New()protected ButtonBase()
Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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 ClickModepublic ClickMode ClickMode { get; set; }
<button ClickMode="clickModeMemberName"/>



Value
ClickMode ClickMode ClickMode

A value of the enumeration that indicates when the Click event occurs.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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 DependencyPropertypublic static DependencyProperty ClickModeProperty { get; }
Value
DependencyProperty DependencyProperty DependencyProperty

The identifier for the ClickMode dependency property.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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 ICommandpublic ICommand Command { get; set; }
<button Command="commandReference"/>

Value
ICommand ICommand ICommand

The command to invoke when this button is pressed. The default is null.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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 objectpublic object CommandParameter { get; set; }
<button>
  <button.CommandParameter>
    object
  </button.CommandParameter>
</button>
Value
object object object

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

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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 DependencyPropertypublic static DependencyProperty CommandParameterProperty { get; }
Value
DependencyProperty DependencyProperty DependencyProperty

The identifier for the CommandParameter dependency property.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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 DependencyPropertypublic static DependencyProperty CommandProperty { get; }
Value
DependencyProperty DependencyProperty DependencyProperty

The identifier for the Command dependency property.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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 boolpublic bool IsPointerOver { get; }
Value
bool bool bool

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

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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 DependencyPropertypublic static DependencyProperty IsPointerOverProperty { get; }
Value
DependencyProperty DependencyProperty DependencyProperty

The identifier for the IsPointerOver dependency property.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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 boolpublic bool IsPressed { get; }
Value
bool bool bool

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

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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 DependencyPropertypublic static DependencyProperty IsPressedProperty { get; }
Value
DependencyProperty DependencyProperty DependencyProperty

The identifier for the IsPressed dependency property.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Events

Click Click Click Click

Occurs when a button control is clicked.

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

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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