gpt4 book ai didi

c# - AutoSuggestBox 不显示结果

转载 作者:太空狗 更新时间:2023-10-29 21:57:29 25 4
gpt4 key购买 nike

我在 Windows Phone 8.1 上的 AutoSuggestBox 中显示结果时遇到问题。我正在使用 MVVM Light 将我的项目源绑定(bind)到 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>

我的 View 模型

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));
}
}
}

对象已设置且不为空。

enter image description here

那他们为什么不出现呢?

更新我的模型

 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 通知用户界面有关您的预测的任何更改(添加或删除)

关于c# - AutoSuggestBox 不显示结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28988040/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com