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
elementInteractive
Returns
GetCommand(Interactive)
Gets CommandProperty.
public static ICommand? GetCommand(Interactive element)
Parameters
elementInteractive
Returns
GetCommandParameter(Interactive)
Gets CommandParameterProperty.
public static object? GetCommandParameter(Interactive element)
Parameters
elementInteractive
Returns
GetEventName(Interactive)
Gets EventNameProperty.
public static string? GetEventName(Interactive element)
Parameters
elementInteractive
Returns
GetPassEventArgs(Interactive)
Gets PassEventArgsProperty.
public static bool GetPassEventArgs(Interactive element)
Parameters
elementInteractive
Returns
GetRoutedEvent(Interactive)
Gets the explicit routed event.
public static RoutedEvent? GetRoutedEvent(Interactive element)
Parameters
elementInteractive
Returns
- RoutedEvent
SetBindings(Interactive, EventBindingCollection?)
Sets BindingsProperty.
public static void SetBindings(Interactive element, EventBindingCollection? value)
Parameters
elementInteractivevalueEventBindingCollection
SetCommand(Interactive, ICommand?)
Sets CommandProperty.
public static void SetCommand(Interactive element, ICommand? value)
Parameters
elementInteractivevalueICommand
SetCommandParameter(Interactive, object?)
Sets CommandParameterProperty.
public static void SetCommandParameter(Interactive element, object? value)
Parameters
elementInteractivevalueobject
SetEventName(Interactive, string?)
Sets EventNameProperty.
public static void SetEventName(Interactive element, string? value)
Parameters
elementInteractivevaluestring
SetPassEventArgs(Interactive, bool)
Sets PassEventArgsProperty.
public static void SetPassEventArgs(Interactive element, bool value)
Parameters
elementInteractivevaluebool
SetRoutedEvent(Interactive, RoutedEvent?)
Sets the explicit routed event.
public static void SetRoutedEvent(Interactive element, RoutedEvent? value)
Parameters
elementInteractivevalueRoutedEvent