I'm trying to build an filter control using RX and WPF. So I have a textbox and a listbox. On start up the listbox has 100 contact names and the user can type in a name to filter the list.
Question is how can I build up an text stream (key inputs) and then publish. This should be Time sensitive so I guess only after 750milliseconds if a key input hasnt been detected then the filter may be performed.
Thanks
The basic outline would looks like so
Here's 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
won't kick off a search every 750ms, only after the user has stopped typing for 750ms. Try this in LinqPad.
Observable.Interval(TimeSpan.FromMilliseconds(10))
.Do(ii => "keystroke".Dump())
.Take(10)
.Throttle(TimeSpan.FromSeconds(0.750))
.Select(ttl => "search")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With