I want to implement ICommand in a separate class, and want to access the button from here:
<Grid>
<Button Command="{StaticResource Do}" >Do!</Button>
</Grid>
public class DoCommand : ICommand
{
public void Execute(object parameter)
{
**I need to access a xaml that triggered this command from here**
}
public bool CanExecute(object parameter)
{
return true;
}
public event EventHandler CanExecuteChanged;
}
How could I do that? Thanks.
You can pass the button as parameter from XAML like this:
Then in Execute method:
public void Execute(object parameter) { Button button = parameter as Button; }