2013-11-28 55 views
0

我使用的是從REST服務獲取數據的AutocompleteBox控件。我的代碼看起來像這樣:AutoCompleteBox WindowsPhone

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; 

我有我需要的所有服務,所以服務工作完美。爲什麼控制不顯示這些價值?雖然回答是空的。數據充滿了單詞。

回答

0

嘗試向AutoCompleteBox添加ValueMemberBinding =「{Binding wordName}」以告知組件應該使用哪個類的哪個屬性。如果不起作用,請添加一個ItemTemplate。