Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AutoSuggestBox not showing results

I'm having trouble displaying the results in the AutoSuggestBox on Windows Phone 8.1. I'm using MVVM Light to bind my itemsource to the Autosuggestbox.

<AutoSuggestBox Header="Van" Text="{Binding SearchTextFrom, Mode=TwoWay}" ItemsSource="{Binding suggestionFrom}">
            <AutoSuggestBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding description}"/>
                </DataTemplate>
            </AutoSuggestBox.ItemTemplate>
            <i:Interaction.Behaviors>
                <core:EventTriggerBehavior EventName="TextChanged">
                    <core:InvokeCommandAction Command="{Binding SearchChangedFrom}">
                    </core:InvokeCommandAction>
                </core:EventTriggerBehavior>
            </i:Interaction.Behaviors>
        </AutoSuggestBox>

My ViewModel

private RelayCommand _SearchChangedFrom;
        public RelayCommand SearchChangedFrom
        {
            get
            {
                return _SearchChangedFrom ?? (_SearchChangedFrom = new RelayCommand(
                    async () =>
                    {
                        if (string.IsNullOrWhiteSpace(user.countrycode))
                        {
                            Debug.WriteLine("Could not autocomplete the country because there was no country code provided.");
                            return;
                        }

                        var predictions = await _Service.GetGoogleMapsSuggestionFromQuery(user.countrycode, SearchTextFrom);
                        suggestionFrom = predictions;
                    }));
            }
        }

private List<Prediction> _suggestionFrom;
        public List<Prediction> suggestionFrom
        {
            get { return _suggestionFrom; }
            set
            {
                Set<List<Prediction>>(() => suggestionFrom, ref _suggestionFrom, value);
                Debug.WriteLine(suggestionFrom.Count + " were received. Displayong them in the autosuggestbox");
                foreach (Prediction prediction in _suggestionFrom)
                {
                    Debug.WriteLine(("Predicition: " + prediction.description));
                }
            }
        }

The objects are set and are not null.

enter image description here

So why don't they show up?

UPDATE My Model

 public class Prediction : ObservableObject
    {
        private string _description;
        public string description
        {
            get { return _description; }
            set{Set<string>(() => description, ref _description, value);}
        }

        private string _id;

        public string id
        {
            get { return _id; } 
            set { Set<string>(() => id, ref _id, value); }
        }

        private List<MatchedSubstring> _matchedSubstrings;
        public List<MatchedSubstring> matched_substrings
        {
            get { return _matchedSubstrings; }
            set{Set<List<MatchedSubstring>>(() => matched_substrings, ref _matchedSubstrings, value);}
        }

        private string _place_id;

        public string place_id
        {
            get { return _place_id; } 
            set { Set<string>(() => place_id, ref _place_id, value); }
        }

        private string _reference;
        public string reference
        {
            get { return _reference; }
            set { Set<string>(() => reference, ref _reference, value); }
        }

        private List<Term> _terms;

        public List<Term> terms
        {
            get { return _terms; }
            set { Set<List<Term>>(() => terms, ref _terms, value); }
        }

        private List<string> _types;
        public List<string> types
        {
            get { return _types; }
            set { Set<List<String>>(() => types, ref _types, value); }
        }

        public override string ToString()
        {
            return this.description;
        }
    }
like image 749
timr Avatar asked Mar 11 '15 13:03

timr


1 Answers

Use

 public ObservableCollection<Prediction> SuggestionFrom { get; set; }

instead

public List<Prediction> SuggestionFrom { get; set; }

ObservableCollection is notify user interface about any changes of your Predictions (add or delete)

like image 197
Boris Salimov Avatar answered Sep 27 '22 22:09

Boris Salimov