0
我希望AutoCompleteBox
可以通過請求在服務器上完成地址。 我有這樣的方法來填充我的AutoCompleteBox:AutoCompleteBox從HttpWebRequest加載數據
private async void getNearStreets()
{
if (acbAddress.Text.Length > 2)
{
ApiRequest request = new ApiRequest("hintAddress", new HintAddress(appSettings.InstanceId, acbAddress.Text, appSettings.SmsCode));
var postData = JsonConvert.SerializeObject(request);
var response = await HttpHelper.SendRequestGetResponse(postData);
ApiResponseTest apiResponse = (ApiResponseTest)JsonConvert.DeserializeObject<ApiResponseTest>(response);
var wordList = this.Resources["autoCompleteWordList"] as AutoCompleteWordList;
wordList.Clear();
foreach (var adresa in apiResponse.data.result)
{
HintAddressResponse adrResponse = (HintAddressResponse)JsonConvert.DeserializeObject<HintAddressResponse>(adresa.ToString());
wordList.Add(adrResponse.street);
}
}
}
這是我的課:
public class AutoCompleteWordList : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private ObservableCollection<string> _listOfAddresses;
public ObservableCollection<string> ListOfAddresses
{
get { return _listOfAddresses; }
set
{
_listOfAddresses = value;
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs("ListOfAddresses"));
}
}
public AutoCompleteWordList()
{
ListOfAddresses = new ObservableCollection<string>();
}
public void Add(string address)
{
ListOfAddresses.Add(address);
}
public void Clear()
{
ListOfAddresses.Clear();
}
}
和看法:
<phone:PhoneApplicationPage.Resources>
<data:AutoCompleteWordList x:Key="autoCompleteWordList" />
</phone:PhoneApplicationPage.Resources>
<toolkit:AutoCompleteBox x:Name="acbAddress" VerticalAlignment="Top"
ItemsSource="{Binding Source={StaticResource autoCompleteWordList}, Path=ListOfAddresses}"
TextChanged="acbAddress_TextChanged"/>
我的問題是,我下載的數據,我將它們添加到集合中,但DropDownDialog不顯示。我想我必須警惕我有新的數據,但我不知道如何。感謝您的幫助