Table of Contents

Class EventToCommand

Namespace
Crystal.Avalonia
Assembly
Crystal.Avalonia.dll

Lightweight attached properties that bridge View events to ViewModel ICommands. Mapped into the default Avalonia XML namespace via XmlnsDefinition — no xmlns prefix required.

public static class EventToCommand
Inheritance
EventToCommand
Inherited Members

Examples

<!-- Single (compiled binding OK on the control) -->
<Button EventToCommand.EventName="Click" EventToCommand.Command="{Binding SaveCommand}" />

<!-- Multiple -->
<Border>
  <EventToCommand.Bindings>
    <EventBinding EventName="PointerPressed" Command="{Binding PressCommand}" PassEventArgs="True"/>
    <EventBinding EventName="DoubleTapped" Command="{Binding OpenCommand}"/>
  </EventToCommand.Bindings>
</Border>

Remarks

Use BindingsProperty for multiple events, or the shorthand EventNameProperty / CommandProperty for a single event. Prefer Avalonia routed events (e.g. Click → ClickEvent).

Fields

BindingsProperty

Multiple event → command mappings.

public static readonly AttachedProperty<EventBindingCollection?> BindingsProperty

Field Value

AttachedProperty<EventBindingCollection>

CommandParameterProperty

Shorthand: command parameter for EventNameProperty.

public static readonly AttachedProperty<object?> CommandParameterProperty

Field Value

AttachedProperty<object>

CommandProperty

Shorthand: command for EventNameProperty.

public static readonly AttachedProperty<ICommand?> CommandProperty

Field Value

AttachedProperty<ICommand>

EventNameProperty

Shorthand: single event name when not using BindingsProperty.

public static readonly AttachedProperty<string?> EventNameProperty

Field Value

AttachedProperty<string>

PassEventArgsProperty

Shorthand: pass event args for EventNameProperty.

public static readonly AttachedProperty<bool> PassEventArgsProperty

Field Value

AttachedProperty<bool>

RoutedEventProperty

Explicit routed event. Takes precedence over EventName and is safe for trimming/AOT.

public static readonly AttachedProperty<RoutedEvent?> RoutedEventProperty

Field Value

AttachedProperty<RoutedEvent>

Methods

GetBindings(Interactive)

Gets BindingsProperty, creating an empty collection if needed so XAML property-element children can be added without a null reference.

public static EventBindingCollection GetBindings(Interactive element)

Parameters

element Interactive

Returns

EventBindingCollection

GetCommand(Interactive)

public static ICommand? GetCommand(Interactive element)

Parameters

element Interactive

Returns

ICommand

GetCommandParameter(Interactive)

public static object? GetCommandParameter(Interactive element)

Parameters

element Interactive

Returns

object

GetEventName(Interactive)

public static string? GetEventName(Interactive element)

Parameters

element Interactive

Returns

string

GetPassEventArgs(Interactive)

public static bool GetPassEventArgs(Interactive element)

Parameters

element Interactive

Returns

bool

GetRoutedEvent(Interactive)

Gets the explicit routed event.

public static RoutedEvent? GetRoutedEvent(Interactive element)

Parameters

element Interactive

Returns

RoutedEvent

SetBindings(Interactive, EventBindingCollection?)

public static void SetBindings(Interactive element, EventBindingCollection? value)

Parameters

element Interactive
value EventBindingCollection

SetCommand(Interactive, ICommand?)

public static void SetCommand(Interactive element, ICommand? value)

Parameters

element Interactive
value ICommand

SetCommandParameter(Interactive, object?)

public static void SetCommandParameter(Interactive element, object? value)

Parameters

element Interactive
value object

SetEventName(Interactive, string?)

public static void SetEventName(Interactive element, string? value)

Parameters

element Interactive
value string

SetPassEventArgs(Interactive, bool)

public static void SetPassEventArgs(Interactive element, bool value)

Parameters

element Interactive
value bool

SetRoutedEvent(Interactive, RoutedEvent?)

Sets the explicit routed event.

public static void SetRoutedEvent(Interactive element, RoutedEvent? value)

Parameters

element Interactive
value RoutedEvent