ButtonBase
ButtonBase
ButtonBase
ButtonBase
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// This API is not available in Javascript.
- Inheritance
- Attributes
| 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:
- Button
- HyperlinkButton
- RepeatButton
- ToggleButton (parent of RadioButton, AppBarToggleButton, CheckBox )
Constructors
ButtonBase() ButtonBase() ButtonBase() ButtonBase()
Provides base class initialization behavior for ButtonBase derived classes.
protected : ButtonBase()protected ButtonBase()Protected Sub New()// This API is not available in Javascript.
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// This API is not available in Javascript.
<button ClickMode="clickModeMemberName"/>
A value of the enumeration that indicates when the Click event occurs.
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// This API is not available in Javascript.
The identifier for the ClickMode dependency property.
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// This API is not available in Javascript.
<button Command="commandReference"/>
- Value
- ICommand ICommand ICommand ICommand
The command to invoke when this button is pressed. The default is null.
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 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// This API is not available in Javascript.
<button>
<button.CommandParameter>
object
</button.CommandParameter>
</button>
- Value
- PlatForm::Object 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// This API is not available in Javascript.
The identifier for the CommandParameter dependency property.
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// This API is not available in Javascript.
The identifier for the Command dependency property.
IsPointerOver 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// This API is not available in Javascript.
- Value
- PlatForm::Boolean 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// This API is not available in Javascript.
The identifier for the IsPointerOver dependency property.
IsPressed 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// This API is not available in Javascript.
- Value
- PlatForm::Boolean 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// This API is not available in Javascript.
The identifier for the IsPressed dependency property.
Events
Click Click Click Click
Occurs when a button control is clicked.
public : event RoutedEventHandler Clickpublic event RoutedEventHandler ClickPublic Event Click// This API is not available in Javascript.
<button Click="eventhandler"/>
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