0

I want to have AutoCompleteBox to complete addresses by request on server. I have this method to fill my 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);
                }
            }
        }

And this is my class:

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

and view:

<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"/>

My problem is that I am downloading data, I added them to collection but DropDownDialog doesn't show up. I think I must alert that I have new data but I don't know how. Thanks for help

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Libor Zapletal
  • 13,752
  • 20
  • 95
  • 182

1 Answers1

0

When I looked at msdn for first time I missed PopulateComplete method. But It's what I need and when I added at end of my method it works.

Libor Zapletal
  • 13,752
  • 20
  • 95
  • 182