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

[Solved] AutoComplete get selected Items In ViewModel

1 Answer 258 Views
AutoComplete
This is a migrated thread and some comments may be shown as answers.
Google
Top achievements
Rank 1
Google asked on 21 Apr 2018, 04:37 AM
How to get Selected Items for xamain form for telerik in radautocomplete.

1 Answer, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 23 Apr 2018, 06:30 AM
Hello,

You could get the selected items of RadAutoComplete through the Tokens collection. Additionally, you could use SuggestionItemSelected event which is fired as soon as new item from the suggestions list is selected.

Hope this will be helpful.

Regards,
Yana
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Neil N
Top achievements
Rank 2
Iron
Iron
Veteran
commented on 12 Feb 2026, 03:18 AM

Old topic but I'm trying to understand the answer for MAUI. The question is asking how to get selected items in the viewmodel, not code behind.  This doesn't seem to work:

XAML:

                            <telerik:RadAutoComplete
                                CompletionMode="Contains"
                                DisplayMode="Tokens"
                                FontSize="15"
                                ItemsSource="{Binding FilteredSkills}"
                                Tokens="{Binding SelectedSkills, Mode=TwoWay}"
                                NoResultsMessage="No matching skill found for the sector chosen. Please choose again."
                                Placeholder="Start typing skills here"
                                SuggestMode="Suggest"
                                SuggestionViewHeight="150"
                                TextColor="Black"
                                TextSearchPath="SkillName" />

VM:

        [ObservableProperty] private ObservableCollection<SkillDTO> _selectedSkills = [];

Didi
Telerik team
commented on 12 Feb 2026, 02:21 PM

Hi Neil,

The tokens collection is a read-only collection, so you cannot use two way binding. 

Here is an approach for MAUI AutoComplete control:

xaml definition:

    <VerticalStackLayout>
        <telerik:RadAutoComplete x:Name="autoCompleteView"
                                        ItemsSource="{Binding Source}"
                                        TextSearchPath="Name" 
                                 Tokens="{Binding SelectedTokens, Mode=OneWayToSource}"
                                        DisplayMode="Tokens"/>

        <Label Text="{Binding SelectedTokens.Count}" />
    </VerticalStackLayout>

and ViewModel with SelectedTokens property and CollectionChanged event:

public partial class MainPage : ContentPage
{
    public MainPage()
    {
        InitializeComponent();
        this.BindingContext = new ViewModel();
    }
}
public class ViewModel : NotifyPropertyChangedBase
{
    private ObservableCollection<object> selection;

    public ViewModel()
    {
        this.Source = new ObservableCollection<Customer>()
            {
                new Customer("Freda Curtis", "fcurtis@mail.com"),
                new Customer("Jeffery Francis", "jfrancis@mail.com"),
                new Customer("Eva Lawson", "elawson@mail.com"),
                new Customer("Emmett Santos", "esantos@mail.com"),
                new Customer("Theresa Bryan", "tbryan@mail.com"),
                new Customer("Jenny Fuller", "jfuller@mail.com"),
                new Customer("Terrell Norris", "tnorris@mail.com"),
            };

    }

    public ObservableCollection<Customer> Source { get; set; }

    public ObservableCollection<object> SelectedTokens {
        get => this.selection;
        set
        {
            if (this.selection != value)
            {
                if (this.selection != null)
                {
                    this.selection.CollectionChanged -= SelectedItems_CollectionChanged;
                }

                this.selection = value;
                Device.StartTimer(TimeSpan.FromMicroseconds(300), () =>
                {
                    this.selection.Add(this.Source[0]);
                    return false;
                });

                this.OnPropertyChanged();

                if (this.selection != null)
                {
                    this.selection.CollectionChanged += SelectedItems_CollectionChanged;
                }
            }
        }
    }
    private void SelectedItems_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
    {
        if (e.Action == NotifyCollectionChangedAction.Add)
        {
            // add your logic here
        }
        else if (e.Action == NotifyCollectionChangedAction.Remove)
        {
            // add your logic here
        }
    }
}
public class Customer
{
    public Customer(string name, string email)
    {
        this.Name = name;
        this.Email = email;
    }
    public string Name { get; set; }
    public string Email { get; set; }
}

Hope this will be of help. In the xaml I have added a label and bind the text to the SelectedTokens.Count, so you can check the items count updates as expected.

 

Neil N
Top achievements
Rank 2
Iron
Iron
Veteran
commented on 26 Feb 2026, 03:55 PM

Thank you. Got this working with a couple tweaks.
Tags
AutoComplete
Asked by
Google
Top achievements
Rank 1
Answers by
Yana
Telerik team
Share this question
or