Skip to main content

TextAlignmentToggleAction Class

Definition

Assembly:Avalonia.Controls.RichTextEditor
Package:Avalonia.Controls.RichTextEditor

Action for setting a specific text alignment on block elements.

public class TextAlignmentToggleAction

Inheritance: BlockPropertyAction<TextAlignment> -> TextAlignmentToggleAction

Constructors

NameDescription
TextAlignmentToggleActionInitializes a new instance of Avalonia.Controls.Documents.Primitives.Actions.TextAlignmentToggleAction for the given alignment.

TextAlignmentToggleAction Constructor

Initializes a new instance of Avalonia.Controls.Documents.Primitives.Actions.TextAlignmentToggleAction for the given alignment.

public TextAlignmentToggleAction(Avalonia.Media.TextAlignment value, string idSuffix, string displayName)

Parameters

value Avalonia.Media.TextAlignment

The alignment this action applies.

idSuffix string

Suffix appended to the action identifier (e.g. "Left").

displayName string

Human-readable name shown in tooltips and menus.

Methods

NameDescription
ExecuteExecutes the action synchronously.
GetAvailableValuesNo summary available.
GetStateGets the current state of the action.
IsCheckedGets whether the action is currently "on" for the selection.

Execute Method

Executes the action synchronously.

public void Execute(Avalonia.Controls.Documents.Primitives.ITextEditorHost host)

Parameters

host Avalonia.Controls.Documents.Primitives.ITextEditorHost

The editor host to execute on.

Remarks

For actions that require async operations (like file dialogs), use Avalonia.Controls.Documents.Primitives.Actions.IEditorAction.ExecuteAsync(Avalonia.Controls.Documents.Primitives.ITextEditorHost) instead.

GetAvailableValues Method

public System.Collections.Generic.IEnumerable<Avalonia.Media.TextAlignment> GetAvailableValues()

Returns

System.Collections.Generic.IEnumerable<Avalonia.Media.TextAlignment>

GetState Method

Gets the current state of the action.

public object GetState(Avalonia.Controls.Documents.Primitives.ITextEditorHost host)

Parameters

host Avalonia.Controls.Documents.Primitives.ITextEditorHost

The editor host to query.

Returns

object

The current state, or null if the action has no state. For toggle actions, this returns a boolean. For property actions, this returns the current property value.

IsChecked Method

Gets whether the action is currently "on" for the selection.

public bool IsChecked(Avalonia.Controls.Documents.Primitives.ITextEditorHost host)

Parameters

host Avalonia.Controls.Documents.Primitives.ITextEditorHost

The editor host to query.

Returns

bool

True if the toggle state is on; otherwise, false.

Remarks

For formatting actions, this returns true if all text in the selection has the formatting applied.

Properties

NameDescription
DisplayNameGets the display name for UI purposes.
IdGets the unique identifier for this action.

DisplayName Property

Gets the display name for UI purposes.

public string DisplayName { get; set; }

Remarks

This is used for tooltips, menu items, and accessibility.

Id Property

Gets the unique identifier for this action.

public string Id { get; set; }

Remarks

IDs follow a hierarchical naming convention:

  • Edit.Undo, Edit.Redo, Edit.Cut, etc.
  • Format.RichBold, Format.RichItalic, etc.
  • Paragraph.AlignLeft, Paragraph.BulletList, etc.