FormattingToggleAction<T> Class
Definition
Base class for toggle formatting actions like RichBold, RichItalic, and RichUnderline.
public class FormattingToggleAction<T>
Remarks
Toggle formatting actions apply or remove a formatting property from the current selection. When the selection is empty, the property is "springloaded" and applied to the next typed character.
Derived classes should specify the Avalonia.Controls.Documents.Primitives.Actions.FormattingToggleAction<T>.Property, Avalonia.Controls.Documents.Primitives.Actions.FormattingToggleAction<T>.OnValue, and Avalonia.Controls.Documents.Primitives.Actions.FormattingToggleAction<T>.OffValue to define the formatting behavior.
Methods
| Name | Description |
|---|---|
| CanExecute | Gets whether the action can currently execute. |
| Execute | Executes the action synchronously. |
| GetState | Gets the current state of the action. |
| IsChecked | Gets whether the action is currently "on" for the selection. |
| ExecuteAsync | Executes 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
| Name | Description |
|---|---|
| DisplayName | Gets the display name for UI purposes. Inherited from EditorAction. |
| Gesture | Gets the optional keyboard gesture for this action. Inherited from EditorAction. |
| Id | Gets the unique identifier for this action. Inherited from EditorAction. |