我正在使用AutocompleteBox控件从REST服务获取数据。我的代码看起来像这样:
MODEL:
public class Word()
{
public int wordId {get;set}
public int wordName {get;set;}
}
XAML:
<toolkit:AutoCompleteBox x:Name="AutoDictionaryTB" Populating="AutoDictionaryTB_Populating_1" HorizontalAlignment="Left" Margin="63,10,0,0" Grid.Row="1" VerticalAlignment="Top" Width="383">
</toolkit:AutoCompleteBox>
背后的代码:
private void AutoDictionaryTB_Populating_1(object sender, PopulatingEventArgs e)
{
var client = new RestClient("http://XXX.XXXX.XX");
var request = new RestRequest("/XXX.XXX.XX", Method.GET);
request.AddParameter("XX", "XX");
request.AddParameter("XX", "XX");
request.AddParameter("XXX", (sender as AutoCompleteBox).Text);
var response2 = client.ExecuteAsync<List<Word>>(request, response =>
{
if (response != null && response.Data != null)
{
AutoDictionaryTB.ItemsSource = response.Data;
AutoDictionaryTB.PopulateComplete();
}
else
{
MessageBox.Show("Unknow error occured. Check your Internet connection or try later.");
}
});
}
在线:
AutoDictionaryTB.ItemsSource = response.Data;
我拥有所需的所有壁垒,因此服务非常完美。为什么控制没有显示这些洞穴?虽然 response.Data 充满了单词,但它是空的。
答案 0 :(得分:0)
尝试添加ValueMemberBinding =&#34; {Binding wordName}&#34;到AutoCompleteBox告诉组件它应该使用哪个类的属性。如果它不起作用,请添加一个ItemTemplate。