Table of Contents

Class SplitButton

Namespace
Avalonia.Controls
Assembly
Avalonia.Controls.dll

A button with primary and secondary parts that can each be pressed separately. The primary part behaves like a Button and the secondary part opens a flyout.

[TemplatePart("PART_PrimaryButton", typeof(Button))]
[TemplatePart("PART_SecondaryButton", typeof(Button))]
[PseudoClasses(new string[] { ":flyout-open", ":pressed" })]
public class SplitButton : ContentControl, INotifyPropertyChanged, IDataContextProvider, ILogical, IThemeVariantHost, IResourceHost, IResourceNode, IStyleHost, ISetLogicalParent, ISetInheritanceParent, ISupportInitialize, IStyleable, INamed, IInputElement, IDataTemplateHost, ISetterValue, ICommandSource
Inheritance
SplitButton
Implements
Derived
Inherited Members
Extension Methods

Constructors

SplitButton()

Initializes a new instance of the SplitButton class.

public SplitButton()

Fields

ClickEvent

Defines the Click event.

public static readonly RoutedEvent<RoutedEventArgs> ClickEvent

Field Value

RoutedEvent<RoutedEventArgs>

CommandParameterProperty

Defines the CommandParameter property.

public static readonly StyledProperty<object?> CommandParameterProperty

Field Value

StyledProperty<object>

CommandProperty

Defines the Command property.

public static readonly StyledProperty<ICommand?> CommandProperty

Field Value

StyledProperty<ICommand>

FlyoutProperty

Defines the Flyout property

public static readonly StyledProperty<FlyoutBase?> FlyoutProperty

Field Value

StyledProperty<FlyoutBase>

HotKeyProperty

Defines the HotKey property.

public static readonly StyledProperty<KeyGesture?> HotKeyProperty

Field Value

StyledProperty<KeyGesture>

Properties

Command

Gets or sets the ICommand invoked when the primary part is pressed.

public ICommand? Command { get; set; }

Property Value

ICommand

CommandParameter

Gets or sets a parameter to be passed to the Command.

public object? CommandParameter { get; set; }

Property Value

object

Flyout

Gets or sets the FlyoutBase that is shown when the secondary part is pressed.

public FlyoutBase? Flyout { get; set; }

Property Value

FlyoutBase

HotKey

Gets or sets an KeyGesture associated with this control

public KeyGesture? HotKey { get; set; }

Property Value

KeyGesture

IsEnabledCore

Allows a derived class to override the enabled state of the control.

protected override bool IsEnabledCore { get; }

Property Value

bool

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().

Methods

CloseFlyout()

Closes the secondary button's flyout.

protected void CloseFlyout()

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 TemplateAppliedEventArgs

The event args.

OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs)

Called when the styled element is added to a rooted logical tree.

protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)

Parameters

e LogicalTreeAttachmentEventArgs

The event args.

OnClickPrimary(RoutedEventArgs?)

Invokes the Click event when the primary button part is clicked.

protected virtual void OnClickPrimary(RoutedEventArgs? e)

Parameters

e RoutedEventArgs

The event args from the internal Click event.

OnClickSecondary(RoutedEventArgs?)

Invoked when the secondary button part is clicked.

protected virtual void OnClickSecondary(RoutedEventArgs? e)

Parameters

e RoutedEventArgs

The event args from the internal Click event.

OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs)

Called when the styled element is removed from a rooted logical tree.

protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)

Parameters

e LogicalTreeAttachmentEventArgs

The event args.

OnFlyoutClosed()

Invoked when the split button's flyout is closed.

protected virtual void OnFlyoutClosed()

OnFlyoutOpened()

Invoked when the split 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 KeyEventArgs

The event args.

OnKeyUp(KeyEventArgs)

Called before the KeyUp event occurs.

protected override void OnKeyUp(KeyEventArgs e)

Parameters

e KeyEventArgs

The event args.

OnPropertyChanged(AvaloniaPropertyChangedEventArgs)

Called when a avalonia property changes on the object.

protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs e)

Parameters

e AvaloniaPropertyChangedEventArgs

OpenFlyout()

Opens the secondary button's flyout.

protected void OpenFlyout()

UpdatePseudoClasses()

Updates the visual state of the control by applying latest PseudoClasses.

protected void UpdatePseudoClasses()

Events

Click

Raised when the user presses the primary part of the SplitButton.

public event EventHandler<RoutedEventArgs>? Click

Event Type

EventHandler<RoutedEventArgs>