AutoComplete for address lookup

2 posts, 0 answers
  1. Craig
    Craig avatar
    4 posts
    Member since:
    May 2016

    Posted 05 Oct Link to this post

    Hi there

    I can't get the AutoComplete control to update it's ItemsSource via data binding.  Everything appears to go smoothly...  I use the OnPropertyChanged event to update the ObservableCollection<string> in the model, and then call RaisePropertyChanged("SearchResults"), but nothing happens client side.  It's still attached to the original list of test items I started with.  I don't replace the ObservableCollection, I'm clearing it and then added the new values.  If I try to replace the collection, the application crashes.

    xaml

    <input:RadAutoComplete
        x:Name="AutoCompleteAddress"
        Watermark="Search here..."
        ItemsSource="{ Binding SearchResults }"
        PropertyChanged="AutoCompleteAddress_OnPropertyChanged"
        CompletionMode="Contains"/>

     

    Code Behind

    private void AutoCompleteAddress_OnPropertyChanged(object sender, PropertyChangedEventArgs e)
    {
        if (e.PropertyName == "Text")
        {
            var addressDetailsPageModel = (AddressDetailsPageModel)BindingContext;
            addressDetailsPageModel.SearchAddress(AutoCompleteAddress.Text.Trim());
        }
    }

     

    Page Model

    public async void SearchAddress(string searchText)
    {
        var searchResults = await _addressSearchService.SearchAsync(searchText);

        SearchResults.Clear();

        foreach (var searchResult in searchResults)
            SearchResults.Add(searchResult);

        RaisePropertyChanged("SearchResults");
    }

    public ObservableCollection<string> SearchResults { get; set; }

     

    Any ideas?

     

    Cheers

  2. Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    503 posts

    Posted 09 Oct Link to this post

    Hello, Craig,

    We are currently working on resolving the crash that is observed when changing the ItemsSource of the AutoComplete at runtime. Here is the feedback item which I suggest you follow in order to receive automatic notifications - AutoComplete exception.

    In the meantime, raising a PropertyChanged event for the ObservableCollection is redundant as the collection provides a built-in functionality of raising property changed when adding/removing items. The behavior is a bug in the iOS/Android implementations of the control from our side. I have logged the behavior in our system - AutoComplete: ObservableCollection notification changes are not respected.You can follow it by subscribing to the item so that you can receive automatic notifications. I have added some points to your account for reporting the issue. In the meantime, we should come up with a fix for the exception thrown when changing the ItemsSource soon so you can use it as a workaround(we expect it to be available with the ServicePack release which is planned for the 18th of October).

    Regards,
    Stefan Nenchev
    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top