C# WPF >> send UI element value to rhino command

You can bind a command to an event using the behaviors (old “interaction”) library. No need for Code Behind while using MVVM:

  xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
[...]
<Button>
         <i:Interaction.Triggers>
                    <i:EventTrigger EventName="PreviewMouseLeftButtonDown">
                        <i:InvokeCommandAction Command="{Binding StarterOnCommand}" />
                    </i:EventTrigger>
                    <i:EventTrigger EventName="PreviewMouseLeftButtonUp">
                        <i:InvokeCommandAction Command="{Binding StarterOffCommand}" />
                    </i:EventTrigger>
         </i:Interaction.Triggers>   
</Button>

You can also pass the event arg as command parameter. Therefore the command needs to allow this.

However, in our team we tend to write event-heavy dialogs in code-behind. But in any case, go for pure code behind or pure mvvm. Mixing both on one view is not great at all.

1 Like