The main outline will look like this
- keydown text event converted to IO
- throttling of keystrokes so that we do not search while the user types.
- Do a search
- Put your search results in the list box.
Here is some pseudo code -
var keysIO = Observable.FromEvent<KeyDownEventHandler, RoutedEventArgs>( h => new KeyDownEventHandler(h), h => btn.KeyDown += h, h => btn.KeyDown -= h)); var searchResults = keysIO.Throttle(TimeSpan.FromSeconds(0.750),Scheduler.Dispatcher); searchResults.Subscribe(sr => { lb.Clear(); lb.AddRange(sr); });
@Andy, Throttle will not start the search every 750 ms, only after the user stops printing for 750 ms. Try this on LinqPad.
Observable.Interval(TimeSpan.FromMilliseconds(10)) .Do(ii => "keystroke".Dump()) .Take(10) .Throttle(TimeSpan.FromSeconds(0.750)) .Select(ttl => "search")
source share