This is a migrated thread and some comments may be shown as answers.

AutocompleteBox Click Event

1 Answer 217 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
Minh
Top achievements
Rank 1
Minh asked on 19 Dec 2017, 09:45 PM
Hi, I was looking to trigger an event when my autocomplete box is clicked into. GotFocus works perfectly but is there a way to have the event not fire when a token is clicked on/ Removed.

Kind regards,

1 Answer, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 22 Dec 2017, 01:43 PM
Hello Minh,

To have better control over which part of the RadAutoCompleteBox should trigger your custom logic, you can handle the MouseLeftButtonDownEvent of the control in a similar fashion:

public MainWindow()
{
    InitializeComponent();
    this.autoComplete.AddHandler(MouseLeftButtonDownEvent, new MouseButtonEventHandler(AutoComplete_MouseLeftButtonDown), true);
}
 
private void AutoComplete_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    var source = e.OriginalSource as FrameworkElement;
 
    // if (source.ParentOfType<RadWatermarkTextBox>() != null)
    if (source.ParentOfType<RadAutoCompleteBoxItem>() == null)
    {
        MessageBox.Show("click");
    }
}

The above two examples will show a message box if the actual text box of the control or anything except an autocomplete box item is clicked. You're free, of course, to further modify this to suit your needs.

Please let me know whether such an approach would work for you.

Regards,
Dilyan Traykov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
AutoCompleteBox
Asked by
Minh
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Share this question
or