When I use the Command
in a Button
control the event handler which joined with Click
event will never raised,
How can I use the Command
and handle the Click
event handler?
You could attach the ICommand to another property and execute it from the Click handler.
<Button x:Name="MyButton" Tag="{x:Static ApplicationCommands.Stop}" Click="MyButton_Click" />
and in the handler:
private void MyButton_Click(object sender, RoutedEventArgs e)
{
var button = sender as Button;
if (button != null)
{
var command = button.Tag as ICommand;
if (command != null)
command.Execute(button.CommandParameter);
}
}
You'd also need to do some extra work if you wanted to keep the Command disabling behavior.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With