Search code examples
c#windows-phone-8wptoolkit

How to get WPT Autocompletebox selection item reference


I am building a windows phone app where I m using the Autocompletebox. I am populating it dynamically through a web search api.

Now If the the user selects the specific item from the autocomplete box, how to get the reference of that specific object.

How I am using it is,

autocompbox.Itsemsource = List<MyClass objects>

Class MyClass
{
  string name;
  ...
  ..
}

name variable is bound on the automcompletebox text. Is there anyway to get which reference is selected? I am using the selectionchanged event, but I dont know the specific property which gives me the specific index of the itemsource.


Solution

  • bind selectedItem in your ViewModel.

    private string _selectedSearch;
    
        public string SelectedSearch
        {
            get { return _selectedSearch; }
            set
            {
                _selectedSearch = value;
                setSearch(_searchValue);
                RaisePropertyChanged(() => SelectedSearch);
            }
        }
    
    private void setSearch(string searchValue){ // to do }
    

    or acces directly like autocomplete.selectedItem