Skip to main content

ListToggleAction Class

Definition​

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

Toggles the current selection or block between a Avalonia.Controls.Documents.List and plain paragraphs.

public class ListToggleAction

Inheritance: object -> EditorAction -> ListToggleAction

Remarks​

When toggled on, wraps all paragraphs in the selection into new Avalonia.Controls.Documents.List elements with one Avalonia.Controls.Documents.ListItem per paragraph. Paragraphs in different parent containers (e.g. separate table cells) each get their own list. When toggled off, unwraps all lists covering the selection.

Two instances are registered in Avalonia.Controls.Documents.Primitives.Actions.EditorActions: one for unordered lists (Disc) and one for ordered lists (Decimal). The Avalonia.Controls.Documents.Primitives.Actions.ListToggleAction.IsChecked(Avalonia.Controls.Documents.Primitives.ITextEditorHost) method checks whether all paragraphs in the selection are inside a list whose marker style belongs to the same category.

Constructors​

NameDescription
ListToggleActionInitializes a new instance with an explicit identifier and name.

ListToggleAction Constructor​

Initializes a new instance with an explicit identifier and name.

public ListToggleAction(Avalonia.Controls.Documents.Primitives.DocumentNodes.TextMarkerStyle defaultMarkerStyle, string id, string displayName)

Parameters​

defaultMarkerStyle Avalonia.Controls.Documents.Primitives.DocumentNodes.TextMarkerStyle

The marker style to use when creating a new list (e.g., Avalonia.Controls.Documents.Primitives.DocumentNodes.TextMarkerStyle.Disc for bulleted or Avalonia.Controls.Documents.Primitives.DocumentNodes.TextMarkerStyle.Decimal for numbered).

id string

The unique action identifier.

displayName string

The human-readable action name.

Remarks​

Use Avalonia.Controls.Documents.Primitives.Actions.EditorActions.ToggleBulletList or Avalonia.Controls.Documents.Primitives.Actions.EditorActions.ToggleNumberedList. An identifier that no built-in action carries leaves the instance unreachable through Avalonia.Controls.Documents.Primitives.Actions.EditorActions.GetById(string).

Methods​

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

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. A toggle action returns a boolean, a property action the current value.

Remarks​

Read Avalonia.Controls.Documents.Primitives.Actions.IToggleAction.IsChecked(Avalonia.Controls.Documents.Primitives.ITextEditorHost) or Avalonia.Controls.Documents.Primitives.Actions.IPropertyAction.GetValueAsObject(Avalonia.Controls.Documents.Primitives.ITextEditorHost) instead. Both say which family the value came from, which an untyped object cannot.

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