Skip to main content

PropertyAction<T> Class

Definition​

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

Base class for property actions that get or set a typed property value.

public class PropertyAction<T>

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

Implements: IEditorAction, IPropertyAction, IPropertyAction<>

Remarks​

Property actions are used for selection-based properties like font family, font size, and colors. They work with combo boxes and other value selectors.

When the selection is empty, property changes are "springloaded" and applied to the next typed character.

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

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

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.