EventToCommand Class
Executes a command in response to a raised event.
Namespace: DevExpress.WinUI.Core
Assembly: DevExpress.WinUI.Core.v23.2.dll
NuGet Package: DevExpress.WinUI
#Declaration
public class EventToCommand :
EventToCommandBase
#Remarks
#Specify an Event Owner
An event owner is an object that raises events. The default event owner object is a control associated with the EventToCommand behavior.
You can use the EventOwner property to specify a different event owner object for the EventToCommand.
<UserControl ...
xmlns:dx="using:DevExpress.WinUI.Core">
<dx:Interaction.Behaviors>
<dx:EventToCommand EventOwner="{x:Bind list}" EventName="DoubleTapped" Command="{x:Bind ShowDetailCommand}"/>
</dx:Interaction.Behaviors>
<!-- ... -->
<ListBox x:Name="list" ... />
</UserControl>
#Specify an Event
Use the EventName property to specify an event for the EventToCommand behavior:
The default EventName property value is Loaded
.
#Pass a Parameter to the Bound Command
Use the CommandParameter property to pass a parameter to a command:
<ListBox x:Name="list">
<dx:Interaction.Behaviors>
<dx:EventToCommand EventName="DoubleTapped" Command="{x:Bind ShowDetailCommand}"
CommandParameter="{x:Bind list.SelectedItem, Mode=OneWay}"/>
</dx:Interaction.Behaviors>
</ListBox>
Use one of the following properties to pass an event’s arguments to a command:
- PassEventArgsToCommand
Specifies if the event’s arguments are passed to the command.
- EventArgsConverter
Allows you to maintain a clean MVVM pattern and convert the event’s arguments to an object suitable for the command.
<ListBox ...> <dx:Interaction.Behaviors> <dx:EventToCommand EventName="DoubleTapped" Command="{x:Bind EditCommand}"> <dx:EventToCommand.EventArgsConverter> <local:CustomEventArgsConverter/> </dx:EventToCommand.EventArgsConverter> </dx:EventToCommand> </dx:Interaction.Behaviors> </ListBox>
#Specify Modifier Keys as an Additional Condition of the Command Execution
Use the ModifierKeys property to specify keys a user should press to invoke the command.
In the code sample below, the bound ShowDetailCommand is invoked when a user presses Alt and clicks or taps a ListBoxItem.
<ListBox ...>
<dx:Interaction.Behaviors>
<dx:EventToCommand EventName="Tapped" Command="{x:Bind ShowDetailCommand}" ModifierKeys="Alt">
<dx:EventToCommand.EventArgsConverter>
<local:ListBoxPointerEventArgsConverter/>
</dx:EventToCommand.EventArgsConverter>
</dx:EventToCommand>
</dx:Interaction.Behaviors>
</ListBox>
#Related API
Property | Description |
---|---|
Allow |
Gets or sets whether the event owner object’s Is |
Dispatcher |
Gets or sets the priority of the Dispatchernull which means that the Dispatcher |
Mark |
Gets or sets whether the associated routed event is marked as handled when the command is executed. This is a dependency property. |
Pass |
Gets or sets whether the event arguments are passed to the command. This is a dependency property. |
Process |
Gets or sets whether the Event |