Thomas V Thomas V - 1 year ago 58
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...");

Answer Source

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:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download