If your AllTags
will contains thousands of elements - I suppose it will be inefficient. In addition, probably, TextChanged
event launches after every tap on the keyboard and data reloading is very frequent which could slow your app.
It is a good idea to take a look at the Reactive Extensions in such cases. With Rx you can easily delay data refreshing when user type very fast and select eg. first 20 elements of the Where
result.
var searchObservable = Observable.FromEventPattern(s => box.TextChanged += s, s => box.TextChanged -= s)
.Throttle(TimeSpan.FromMilliseconds(400))
.Select(result =>
{
var textBox = result.Sender as AutoSuggestBox;
return textBox.Text;
}
);
searchObservable
.DistinctUntilChanged()
.ObserveOnDispatcher()
.Subscribe(searchString =>
{
//Select elements from 'AllTags' here, this code will be launched with 400ms delay (throttle) when user is typing fast.
}
Note, this example is very general, but you can base on it.
At first glance, Rx looks difficult, but there are a lot of topics and tutorials about it.