This is a migrated thread and some comments may be shown as answers.

AutoComplete for address lookup

4 Answers 169 Views
AutoComplete
This is a migrated thread and some comments may be shown as answers.
Craig
Top achievements
Rank 1
Craig asked on 05 Oct 2017, 06:58 AM

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

4 Answers, 1 is accepted

Sort by
0
Stefan Nenchev
Telerik team
answered on 09 Oct 2017, 02:01 PM
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
0
Umair
Top achievements
Rank 1
answered on 04 Nov 2017, 02:45 PM

Hi,

any Updates on this?

I want to assign values to the Autocomplete. please note, the values are retrieved from the server using async operation. 

0
Umair
Top achievements
Rank 1
answered on 06 Nov 2017, 08:54 AM

Found a solution and it's working for me

public static readonly BindableProperty ItemsProperty =
              BindableProperty.Create("Items", typeof(IEnumerable<object>), typeof(MyAutocomplete), default(IEnumerable<object>),
                  defaultBindingMode: BindingMode.TwoWay,
                  propertyChanging: (bindable, oldValue, newValue) =>
                  {
                      MyAutocomplete_ = (MyAutocomplete)bindable;
                      _.ItemsSource = new List<object>(); // does the trick
                      _.ItemsSource = (IEnumerable)newValue;
                  });
0
Stefan Nenchev
Telerik team
answered on 08 Nov 2017, 11:34 AM
Hello, Umair,

Thank you for sharing the approach with the community.

In the meantime, I can confirm that the issue where changing the ItemsSource at runtime results in an exception is fixed with R3 2017 SP. We have not started working on the second one though.

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
Tags
AutoComplete
Asked by
Craig
Top achievements
Rank 1
Answers by
Stefan Nenchev
Telerik team
Umair
Top achievements
Rank 1
Share this question
or