Skip to main content

BlockBorderToggleAction Class

Definition

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

Action for toggling block borders on/off for affected blocks.

public class BlockBorderToggleAction

Inheritance: object -> EditorAction -> BlockBorderToggleAction

Remarks

Targets every block-level element covered by the selection. When a paragraph sits inside a Avalonia.Controls.Documents.TableCell, the cell is preferred over the inner paragraph so the border wraps the cell; outside of tables the paragraph itself is the target. When the document is empty, an implicit Paragraph is materialized so the user can apply a border before typing — same convention as text input and the other block-level actions.

Constructors

NameDescription
BlockBorderToggleActionNo summary available.

BlockBorderToggleAction Constructor

public BlockBorderToggleAction()

Methods

NameDescription
CanExecuteGets whether the action can currently execute.
ExecuteExecutes the action synchronously.
GetStateGets the current state of the action.
IsCheckedGets whether the action is currently "on" for the selection.
ExecuteAsyncExecutes the action asynchronously. Inherited from EditorAction.

CanExecute Method

Gets whether the action can currently execute.

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

Parameters

host Avalonia.Controls.Documents.Primitives.ITextEditorHost

The editor host to check against.

Returns

bool

True if the action can execute; otherwise, false.

Remarks

This is called frequently to update UI state (button enabled/disabled). Implementations should be fast and avoid heavy computation.

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.

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.
GestureGets the optional keyboard gesture for this action. Inherited from EditorAction.

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.