views:

99

answers:

1

Hello,

I've a simple question about commands in WPF : I have a button with an ICommand bound to the Command property, and when I click on this button, the command is started, and wow it works :)

Now I whant to start a particular command when I'm just pushing down the button (MouseLeftButtonDown event I think), but I don't know how can I put multiple commands to one button, and specify the event who will start the command.

Do you have any idea ? Maybe a custom control ?

Thanks for you help,
Antoine.

+1  A: 

You might consider basing your own class on Button and extending it with your own set of Command, CommandTarget and CommandParameter-like properties (possibly even DependencyProperty. When you want to fire the command, just do this:

 void FireCommand()
 {
    var routedCommand = Command as RoutedCommand;
    if (routedCommand != null)
    {
       routedCommand.Execute(CommandParameter, CommandTarget);
    }
    else if (Command != null)
    {
       Command.Execute(CommandParameter);
    }
 }
wpfwannabe
Ok, so I'll create a custom control based on a button, with some new dependecy property that can get ICommand, and when the event MouseLeftButtonDown is fired I start the right command like you wrote ... Thank you :)
ThitoO