问题描述
限时送ChatGPT账号..我正在尝试使用 RX 和 WPF 构建过滤器控件.所以我有一个文本框和一个列表框.启动时,列表框有 100 个联系人姓名,用户可以输入姓名来过滤列表.
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.
问题是如何建立文本流(关键输入)然后发布.这应该是时间敏感的,所以我猜只有在 750 毫秒后,如果没有检测到关键输入,则可以执行过滤器.
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.
谢谢
推荐答案
基本大纲应该是这样
textbox keydown 事件转换为 IO限制击键,这样我们就不会在用户实际输入时进行搜索进行搜索将搜索结果放到列表框中这是一些伪代码 -
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
不会每 750 毫秒开始一次搜索,只有在用户停止输入 750 毫秒后才会开始.在 LinqPad 中试试这个.
@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")
这篇关于RX 自动完成框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论