Class Button
A standard button control.
[PseudoClasses(new string[] { ":flyout-open", ":pressed" })]
public class Button : ContentControl, INotifyPropertyChanged, IDataContextProvider, ILogical, IThemeVariantHost, IResourceHost, IResourceNode, IStyleHost, ISetLogicalParent, ISetInheritanceParent, ISupportInitialize, IStyleable, INamed, IInputElement, IDataTemplateHost, ISetterValue, ICommandSource
- Inheritance
-
Button
- Implements
- Derived
- Inherited Members
- Extension Methods
Constructors
Button()
Initializes a new instance of the Button class.
public Button()
Fields
ClickEvent
Defines the Click event.
public static readonly RoutedEvent<RoutedEventArgs> ClickEvent
Field Value
ClickModeProperty
Defines the ClickMode property.
public static readonly StyledProperty<ClickMode> ClickModeProperty
Field Value
CommandParameterProperty
Defines the CommandParameter property.
public static readonly StyledProperty<object?> CommandParameterProperty
Field Value
CommandProperty
Defines the Command property.
public static readonly StyledProperty<ICommand?> CommandProperty
Field Value
FlyoutProperty
Defines the Flyout property
public static readonly StyledProperty<FlyoutBase?> FlyoutProperty
Field Value
HotKeyProperty
Defines the HotKey property.
public static readonly StyledProperty<KeyGesture?> HotKeyProperty
Field Value
IsCancelProperty
Defines the IsCancel property.
public static readonly StyledProperty<bool> IsCancelProperty
Field Value
IsDefaultProperty
Defines the IsDefault property.
public static readonly StyledProperty<bool> IsDefaultProperty
Field Value
IsPressedProperty
Defines the IsPressed property.
public static readonly DirectProperty<Button, bool> IsPressedProperty
Field Value
Properties
ClickMode
Gets or sets a value indicating how the Button should react to clicks.
public ClickMode ClickMode { get; set; }
Property Value
Command
Gets or sets an ICommand to be invoked when the button is clicked.
public ICommand? Command { get; set; }
Property Value
CommandParameter
Gets or sets a parameter to be passed to the Command.
public object? CommandParameter { get; set; }
Property Value
Flyout
Gets or sets the Flyout that should be shown with this button.
public FlyoutBase? Flyout { get; set; }
Property Value
HotKey
Gets or sets an KeyGesture associated with this control
public KeyGesture? HotKey { get; set; }
Property Value
IsCancel
Gets or sets a value indicating whether the button is the Cancel button for the window.
public bool IsCancel { get; set; }
Property Value
IsDefault
Gets or sets a value indicating whether the button is the default button for the window.
public bool IsDefault { get; set; }
Property Value
IsEnabledCore
Allows a derived class to override the enabled state of the control.
protected override bool IsEnabledCore { get; }
Property Value
Remarks
Derived controls may wish to disable the enabled state of the control without overwriting the user-supplied IsEnabled setting. This can be done by overriding this property to return the overridden enabled state. If the value returned from IsEnabledCore should change, then the derived control should call UpdateIsEffectivelyEnabled().
IsPressed
Gets or sets a value indicating whether the button is currently pressed.
public bool IsPressed { get; }
Property Value
Methods
CloseFlyout()
Closes the button's flyout.
protected virtual void CloseFlyout()
OnAccessKey(RoutedEventArgs)
This method is used to execute the action on an effective IInputElement when a corresponding access key has been invoked. By default, the Focus() method is invoked with the NavigationMethod.Tab to indicate a visual focus adorner. Overwrite this method if other methods or additional functionality is needed when an item should receive the focus.
protected override void OnAccessKey(RoutedEventArgs e)
Parameters
e
RoutedEventArgsAccessKeyEventArgs are passed on to indicate if there are multiple matches or not.
OnApplyTemplate(TemplateAppliedEventArgs)
Called when the control's template is applied. In simple terms, this means the method is called just before the control is displayed.
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
Parameters
e
TemplateAppliedEventArgsThe event args.
OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs)
Called when the styled element is added to a rooted logical tree.
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
Parameters
e
LogicalTreeAttachmentEventArgsThe event args.
OnAttachedToVisualTree(VisualTreeAttachmentEventArgs)
Called when the control is added to a rooted visual tree.
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
Parameters
e
VisualTreeAttachmentEventArgsThe event args.
OnClick()
Invokes the Click event.
protected virtual void OnClick()
OnCreateAutomationPeer()
Returns a new, type-specific AutomationPeer implementation for the control.
protected override AutomationPeer OnCreateAutomationPeer()
Returns
- AutomationPeer
The type-specific AutomationPeer implementation.
OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs)
Called when the styled element is removed from a rooted logical tree.
protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
Parameters
e
LogicalTreeAttachmentEventArgsThe event args.
OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs)
Called when the control is removed from a rooted visual tree.
protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)
Parameters
e
VisualTreeAttachmentEventArgsThe event args.
OnFlyoutClosed()
Invoked when the button's flyout is closed.
protected virtual void OnFlyoutClosed()
OnFlyoutOpened()
Invoked when the button's flyout is opened.
protected virtual void OnFlyoutOpened()
OnKeyDown(KeyEventArgs)
Called before the KeyDown event occurs.
protected override void OnKeyDown(KeyEventArgs e)
Parameters
e
KeyEventArgsThe event args.
OnKeyUp(KeyEventArgs)
Called before the KeyUp event occurs.
protected override void OnKeyUp(KeyEventArgs e)
Parameters
e
KeyEventArgsThe event args.
OnLostFocus(RoutedEventArgs)
Called before the LostFocus event occurs.
protected override void OnLostFocus(RoutedEventArgs e)
Parameters
e
RoutedEventArgsThe event args.
OnPointerCaptureLost(PointerCaptureLostEventArgs)
Called before the PointerCaptureLost event occurs.
protected override void OnPointerCaptureLost(PointerCaptureLostEventArgs e)
Parameters
e
PointerCaptureLostEventArgsThe event args.
OnPointerPressed(PointerPressedEventArgs)
Called before the PointerPressed event occurs.
protected override void OnPointerPressed(PointerPressedEventArgs e)
Parameters
e
PointerPressedEventArgsThe event args.
OnPointerReleased(PointerReleasedEventArgs)
Called before the PointerReleased event occurs.
protected override void OnPointerReleased(PointerReleasedEventArgs e)
Parameters
e
PointerReleasedEventArgsThe event args.
OnPropertyChanged(AvaloniaPropertyChangedEventArgs)
Called when a avalonia property changes on the object.
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
Parameters
change
AvaloniaPropertyChangedEventArgsThe property change details.
OpenFlyout()
Opens the button's flyout.
protected virtual void OpenFlyout()
UpdateDataValidation(AvaloniaProperty, BindingValueType, Exception?)
Called to update the validation state for properties for which data validation is enabled.
protected override void UpdateDataValidation(AvaloniaProperty property, BindingValueType state, Exception? error)
Parameters
property
AvaloniaPropertyThe property.
state
BindingValueTypeThe current data binding state.
error
ExceptionThe current data binding error, if any.
Events
Click
Raised when the user clicks the button.
public event EventHandler<RoutedEventArgs>? Click