I have three Buttons associated with the same command:
<StackPanel>
<Button Name="Btn1" Content="Test 1" Command="{Binding CmdDoSomething}" />
<Button Name="Btn2" Content="Test 2" Command="{Binding CmdDoSomething}" />
<Button Name="Btn3" Content="Test 3" Command="{Binding CmdDoSomething}" />
</StackPanel>
How can I tell which Button invoked the command or pass this information to the method call?
CmdDoSomething = new DelegateCommand(
x => DvPat(),
y => true
);
Here's my DelegateCommand Class:
public class DelegateCommand : ICommand
{
public event EventHandler CanExecuteChanged;
public void RaiseCanExecuteChanged() => CanExecuteChanged?.Invoke(this, EventArgs.Empty);
private readonly Predicate<object> _canExecute;
public bool CanExecute(object parameter) => _canExecute == null ? true : _canExecute(parameter);
private readonly Action<object> _execute;
public void Execute(object parameter) => _execute(parameter);
public DelegateCommand(Action<object> execute) : this(execute, null) { }
public DelegateCommand(Action<object> execute, Predicate<object> canExecute)
{
_execute = execute;
_canExecute = canExecute;
}
}