0

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.

user88975
  • 610
  • 1
  • 9
  • 18

1 Answers1

2

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

MatDev8
  • 976
  • 5
  • 18
  • I dont want to to a search in the list again and find out which item is selected.are you saying autocomplete.selecteditem will return the myclass typed object? – user88975 Mar 21 '14 at 14:44
  • You can just put a list for itemsource for autocompleteBox. My exemple is for get SelectedItem and after set your list for see the item match – MatDev8 Mar 21 '14 at 15:32
  • SelectionChanged event will help you in you don't use MVVM pattern – MatDev8 Mar 21 '14 at 15:33
  • Thanks. It returned me the same type object that I can cast...It worked. – user88975 Mar 21 '14 at 15:46