Thomas V Thomas V - 4 months ago 19
C# Question

What event(s) trigger a command in a button?

so i have a question relating to a project i'm working on:

what events are used to trigger a command in a button control? is it only the click event?

because when i click on a button my command will be executed after my mouse button is released? so thats why i want to know.

<Button x:Name="ClickButton" Content="Click here" HorizontalAlignment="Left" Margin="325,123,0,0" VerticalAlignment="Top" Width="75" Command="{Binding ClickHereCommand}"/>

Code in the ViewModel

public ICommand ClickHereCommand => (new CommandHandler(() => IsGoingUp(), _canExecute));

public void IsGoingUp()
Console.WriteLine("Moving up...");


By default, the Command property is indeed bound to the Click event. You can bind your Command property to other events as shown here:

Though if you just want to bind your Command to another mouse event, the ClickMode property is what you're looking for: