Button​Base Button​Base Button​Base Class

Definition

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

public : class ButtonBase : ContentControl, IButtonBasepublic class ButtonBase : ContentControl, IButtonBasePublic Class ButtonBase Inherits ContentControl Implements IButtonBase
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

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

Remarks

ButtonBase derived classes

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

Constructors

ButtonBase() ButtonBase() ButtonBase()

Provides base class initialization behavior for ButtonBase derived classes.

protected : ButtonBase()protected ButtonBase()Protected Sub New()
Attributes

Properties

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"/>



Value
ClickMode ClickMode ClickMode

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

Attributes

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

Identifies the ClickMode dependency property.

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

The identifier for the ClickMode dependency property.

Attributes

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"/>

Value
ICommand ICommand ICommand

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

Attributes

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 Windows::UI::Xaml::Input::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 Windows::UI::Xaml::Input::ICommand for C++ code and System.Windows.Input.ICommand for Microsoft .NET code.

CommandParameter CommandParameter CommandParameter

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

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

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

Attributes

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
Value
DependencyProperty DependencyProperty DependencyProperty

The identifier for the CommandParameter dependency property.

Attributes

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
Value
DependencyProperty DependencyProperty DependencyProperty

The identifier for the Command dependency property.

Attributes

IsPointerOver IsPointerOver IsPointerOver

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

public : PlatForm::Boolean IsPointerOver { get; }public bool IsPointerOver { get; }Public ReadOnly Property IsPointerOver As bool
Value
PlatForm::Boolean bool bool

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

Attributes

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
Value
DependencyProperty DependencyProperty DependencyProperty

The identifier for the IsPointerOver dependency property.

Attributes

IsPressed IsPressed IsPressed

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

public : PlatForm::Boolean IsPressed { get; }public bool IsPressed { get; }Public ReadOnly Property IsPressed As bool
Value
PlatForm::Boolean bool bool

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

Attributes

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
Value
DependencyProperty DependencyProperty DependencyProperty

The identifier for the IsPressed dependency property.

Attributes

Events

Click Click Click

Occurs when a button control is clicked.

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

Attributes

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