# Commands

The Buttons implement the `ICommandSource` interface which provides a command support where any button can be bound to an `ICommand` object that will be executed on click.

The `ICommandSource` interface adds the following properties to the RadButton classes:

* `Command`—The `ICommand` object that will be executed on button click.

* `CommandParameter`—The `object` that will be passed as the parameter of the `Execute` method of the command.

* `CommandTarget`—The `UIElement` on which the command is being executed.

> tip The [DelegateCommand](https://www.telerik.com/winui/documentation/common/mvvm-helpers/delegatecommand) class is a relay command implementation that can be easily used in your view models. It implements the `ICommand` interface and allows you to provide two actions - `Execute` and `CanExecute`.

The following example demonstrates how to data bind the `Command` property of [RadButton](https://www.telerik.com/winui/documentation/controls/radbuttons/button) to an `ICommand` property of the view model. The same approach can be used also with the other buttons from the suite - like `RadToggleButton`, `RadRadioButton`, etc.

1. Create a view model class and define the command property.

#### **Defining the view model**

```C#
public class SampleViewModel
{
	public ICommand MyCommand { get; set; }

	public SampleViewModel()
	{
		MyCommand = new DelegateCommand(OnCommandExecuted);
	}
	
	private void OnCommandExecuted(object obj)
	{
		string parameter = (string)obj; // where parameter will be "ParameterValue" coming from the CommandParameter set on the button
	} 
}
```

1. Assing the view model to the DataContext property of the button or the view that hosts it.

#### **Setting up the DataContext**

```C#
public UserControl()
{
	InitializeComponent();
	this.button.DataContext = new SampleViewModel();
}
```

1. Set command properties in XAML.

#### **Setting up the Command and CommandParameter properties**

```XAML
<telerik:RadButton x:Name="button" Content="My Button"
				Command="{Binding MyCommand}"
				CommandParameter="ParameterValue" />
```

## See Also

* [Getting Started](https://www.telerik.com/winui/documentation/controls/radbuttons/getting-started)
* [Events](https://www.telerik.com/winui/documentation/controls/radbuttons/events)
