我是一名 Rx 新手,试图弄清楚如何使用 Rx 处理鼠标手势。我在某处找到了这个解决方案:
var mouseMove = Observable.FromEventPattern<MouseEventArgs>(this, "MouseMove");
var lMouseDown = Observable.FromEventPattern<MouseEventArgs>(this, "MouseDown")
.Where(e => e.EventArgs.Button == MouseButtons.Left);
var lMouseUp = Observable.FromEventPattern<MouseEventArgs>(this, "MouseUp")
.Where(e => e.EventArgs.Button == MouseButtons.Left);
var dragSequence =
from down in lMouseDown
from move in mouseMove.StartWith(down).TakeUntil(lMouseUp)
select move;
dragSequence.ObserveOn(this).Subscribe(e => Trace.WriteLine(e.EventArgs.Location));
但是多个独立的鼠标手势都是同一流的一部分。所以我不能对 onCompleted 使用处理程序;序列永远不会完成。我想为每次拖动将流分成单独的序列,我该怎么做?