RX 自动完成框

编程入门 行业动态 更新时间:2024-10-27 10:19:35
本文介绍了RX 自动完成框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送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:关键词]

本文发布于:2023-05-01 12:31:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1409323.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自动完成   RX

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!