# Commands

RadAutoSuggestBox executes its search and clear query actions using a couple of commands.

To replace the default actions of the commands, you can implement the **ICommand** interface (or use the Telerik's [DelegateCommand](https://www.telerik.com/products/wpf/documentation/common-information/mvvm-helpers/common-delegate-command) implementation) and set the **ClearButtonCommand** and **QueryButtonCommand** properties of RadAutoSuggestBox.

The following example shows how to setup two DelegateCommand objects which implement ICommand and assign the custom commands to the corresponding properties in order to replace the default search and clear behaviors.

**Example 1: Setting up the view**

```XAML
<telerik:RadAutoSuggestBox x:Name="radAutoSuggestBox" />
```

> tip See how to setup a runnable RadAutoSuggestBox example in the [Getting Started](https://www.telerik.com/products/wpf/documentation/controls/radautosuggestbox/getting-started) article.

**Example 2: Implementing and assigning the commands**

```C#
public MyMainWindow()
{
    InitializeComponent();
    this.radAutoSuggestBox.QueryButtonCommand = new DelegateCommand(OnQueryExecuted);
    this.radAutoSuggestBox.ClearButtonCommand = new DelegateCommand(OnClearExecuted);
}

private void OnClearExecuted(object obj)
{
    this.radAutoSuggestBox.Text = string.Empty;
    this.radAutoSuggestBox.IsDropDownOpen = false;
}

private void OnQueryExecuted(object obj)
{
    // Where List<CountrInfo> is the user defined collection with bussiness objects
    var source = (List<CountryInfo>)this.radAutoSuggestBox.ItemsSource;
    var queryResult = source.FirstOrDefault(x => x.Name.ToLowerInvariant().Contains(this.radAutoSuggestBox.Text));
    if (queryResult != null)
    {
        this.radAutoSuggestBox.Text = queryResult.Name;
    }
    this.radAutoSuggestBox.IsDropDownOpen = false;
}
```

## See Also

* [Getting Started](https://www.telerik.com/products/wpf/documentation/controls/radautosuggestbox/getting-started)
* [Buttons](https://www.telerik.com/products/wpf/documentation/controls/radautosuggestbox/appearance/customize-buttons)
