0

我想必须AutoCompleteBox通过服务器上的请求来完成地址。我有这个方法来填充我的 AutoCompleteBox:

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 没有出现。我想我必须提醒我有新数据,但我不知道如何。感谢帮助

4

1 回答 1

0

当我第一次查看 msdn 时,我错过了 PopulateComplete 方法。但这是我需要的,当我在我的方法结束时添加它时它可以工作。

于 2013-02-21T16:09:24.577 回答