Last Updated: 26 Feb 2018 10:53 by ADMIN
Lance | Team Lead - US DevTools Support
Created on: 17 Jul 2017 15:19
Category: UI for Xamarin
Type: Feature Request
AutoCompleteBox: Make Tokens an ObservableCollection<object>
Currently, the AutoCompleteBox's Tokens property is of type Collection<object>, this presents a problem when adding and removing items programmatically as there is no observability.

When an item is added or removed, the UI is not updated even though the token s collection has been. 

Here is a simple repro:

private void RadListView_OnItemTapped(object sender, ItemTapEventArgs e)
    // For this example e.Item is of type string

    (autoComplete.Tokens as Collection<object>)?.Add(e?.Item);

    // Item is added, but UI is not updated
    Debug.WriteLine($"Tokens count: {(autoComplete.Tokens as Collection<object>)?.Count}");

1 comment
Pavel R. Pavlov
Posted on: 18 Jul 2017 10:46
The Tokens collection is read only hence tokens must be created by the underlying native components. Customers are only allowed to get the already created tokens. In order to be notified when a token is added to the Tokens collection, customers can use a OneWayToSource binding to the property. The underlying collection is ObservableCollection<object> meaning that every update of the Tokens will be reflected and customers will be notified that the end user has created/deleted a token. For even more details customers can subscribe to the CollectionChanged event of their collection.