문제

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.

도움이 되었습니까?

해결책

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);
    }
 }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top