在Windows Phone 8.1上的AutoSuggestBox中显示结果时遇到问题。我正在使用mvvm light将itemsource绑定到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>

我的视图模型
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));
                }
            }
        }

对象已设置且不为空。
为什么他们不出现?
更新
我的模型
 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;
        }
    }

最佳答案

使用

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

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

ObservableCollection是通知用户界面有关预测的任何更改(添加或删除)

07-26 04:46