Skip to main content

BlockPropertyAction<T> Class

Definition

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

Base class for block-level property actions.

public class BlockPropertyAction<T>

Inheritance: object -> EditorAction -> BlockPropertyAction<T>

Implements: IBlockPropertyAction, IBlockPropertyAction<>, IEditorAction, IPropertyAction

Remarks

This base class provides common functionality for actions that modify properties on Block elements (Paragraph, Section, etc.).

When the selection spans multiple blocks, all affected blocks have their property set. Override Avalonia.Controls.Documents.Primitives.Actions.BlockPropertyAction<T>.ResolveTargetElements(Avalonia.Controls.Documents.Primitives.ITextEditorHost) to change the set of elements that are modified (e.g. target Avalonia.Controls.Documents.TableCell instead of Avalonia.Controls.Documents.Paragraph).

Derived classes only need to:

  • Specify the target StyledProperty
  • Provide metadata (Id, DisplayName, Gesture)
  • Return available values if applicable

Methods

NameDescription
CanExecuteGets whether the action can currently execute.
ExecuteExecutes the action synchronously.
GetAvailableValuesNo summary available.
GetStateGets the current state of the action.
GetValueNo summary available.
HasConsistentValueGets whether all affected blocks have the same value for this property.
SetValueNo summary available.
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.

GetAvailableValues Method

public System.Collections.Generic.IEnumerable<T> GetAvailableValues()

Returns

System.Collections.Generic.IEnumerable<T>

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.

GetValue Method

public T GetValue(Avalonia.Controls.Documents.Primitives.ITextEditorHost host)

Parameters

host Avalonia.Controls.Documents.Primitives.ITextEditorHost

Returns

T

HasConsistentValue Method

Gets whether all affected blocks have the same value for this property.

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

Parameters

host Avalonia.Controls.Documents.Primitives.ITextEditorHost

The editor host.

Returns

bool

True if all affected blocks have the same property value. False if blocks have different values (mixed state).

Remarks

UI controls should show a mixed/indeterminate state when this returns false. For example, a ComboBox might show "Mixed" placeholder text.

For collapsed selections, this always returns true (single block).

SetValue Method

public void SetValue(Avalonia.Controls.Documents.Primitives.ITextEditorHost host, T value)

Parameters

host Avalonia.Controls.Documents.Primitives.ITextEditorHost

value T

Properties

NameDescription
DisplayNameGets the display name for UI purposes. Inherited from EditorAction.
GestureGets the optional keyboard gesture for this action. Inherited from EditorAction.
IdGets the unique identifier for this action. Inherited from EditorAction.