使用反应性扩展来协调和调整简化Control.Enabled =真/假条件? [英] Use Reactive Extensions to harmonize & simplify Control.Enabled = true/false conditions?

查看:60
本文介绍了使用反应性扩展来协调和调整简化Control.Enabled =真/假条件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以或更准确地讲,如何使用RX.Net侦听许多不同形式的(WinForms)控件的.TextChanged/.RowsChanged/.SelectionChanged事件以及何时满足一个条件(ControlA) .Text不为空,ControlB.RowsCount> 0等)启用一个DoSomething按钮.

Is it possible, or more precisely how is it possible to use RX.Net to listen to a number and different variety of (WinForms) controls' .TextChanged/.RowsChanged/.SelectionChanged events and whenever one condition is fullfilled (ControlA.Text isn't empty, ControlB.RowsCount > 0 etc) enable that one DoSomething button.

我问,因为当前我们在每个事件的处理程序中都有一个长的if/then语句,如果条件由于重复的代码而导致条件改变,则维护它们,这很容易出错,这就是为什么我认为这样的原因采取事件流并将条件放在一个地方会很好.

I am asking because currently we have a lengthy if/then statement in each of these events' handlers and maintaining them if the condition changes is, due to duplicate code, quite error prone and that's why, if possible, I think it would be nice to take the stream of events and put the condition in one place.

有人这样做吗?

推荐答案

您可以将Observable.FromEventPattern与Join模式结合使用,并结合使用Observable.When,Observable.And和Observable.Then,从而创建可观察的对象,具体取决于各种条件,例如事件的组合.例如,在这里考虑我的答案:

You can use Observable.FromEventPattern in combination with Join patterns, with Observable.When, Observable.And and Observable.Then, to create observables which will fire depending on various conditions, like combinations of events. For example, consider my answer here: Reactive Extensions for .NET (Rx): Take action once all events are completed

这篇关于使用反应性扩展来协调和调整简化Control.Enabled =真/假条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆