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, 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.
ClearValueClears the property value for the selection, reverting affected elements to their inherited or default value.
ExecuteExecutes the action synchronously.
ExecuteAsyncExecutes the action asynchronously. Inherited from EditorAction.
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.

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.

ClearValue Method​

Clears the property value for the selection, reverting affected elements to their inherited or default value.

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

Parameters​

host Avalonia.Controls.Documents.Primitives.ITextEditorHost

The editor host to modify.

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​

A property action carries no value of its own, so plain invocation does nothing: the value arrives through Avalonia.Controls.Documents.Primitives.Actions.BlockPropertyAction<T>.SetValue(Avalonia.Controls.Documents.Primitives.ITextEditorHost,`0) from the picker bound to the action. This matches Avalonia.Controls.Documents.Primitives.Actions.PropertyAction<T>.Execute(Avalonia.Controls.Documents.Primitives.ITextEditorHost). The member is on Avalonia.Controls.Documents.Primitives.Actions.IEditorAction and therefore reachable from any tool, including a Avalonia.Controls.Documents.Primitives.Toolbar.ButtonTool a consumer binds to EditorActions.Margin; a no-op leaves that button inert instead of faulting the click handler's task.

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. 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.

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.