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 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
<telerik:RadAutoSuggestBox x:Name="radAutoSuggestBox" />
See how to setup a runnable RadAutoSuggestBox example in the Getting Started article.
Example 2: Implementing and assigning the commands
public MainWindow()
{
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;
}