我正在尝试使用一对主题类来触发 2 组事件序列。该应用程序是一个绘图应用程序,其中一个主体在用户单击时触发 onNext,而另一个主体在用户双击时触发 OnNext。我已经编写了 GetClick 和 GetDoubleClick 方法,它们为上述情况返回一个 observable 并且似乎工作正常。下面代码中的问题是,如果在第一个触发点击序列的主题上调用 onNext,双击 observable 永远不会被调用。如果我注释掉第一个主题的 onNext 调用,双击 observable 确实会按预期触发。任何人都可以看看下面的代码和他们的想法/想法吗?我在下面的问题代码行中添加了注释
public static KeyValuePair<IObservable<MapPoint>, IObservable<PointCollection>>
DrawPointsDynamic(this Map map)
{
PointCollection pc = new PointCollection();
Subject<Point> ptSubject = new Subject<Point>();
Subject<PointCollection> ptsSubject = new Subject<PointCollection>();
IObservable<Point> ptObs = ptSubject.Hide();
IObservable<PointCollection> ptsObs = ptsSubject.Hide();
map.GetClick()
.Subscribe(next =>
{
var p = map.ScreenToMap(next.EventArgs.GetPosition(map));
ptSubject.OnNext(p); //If I leave this line in, the subscription to the doubleClick below does not get called. If comment it out, the subscription below does get called as expected;
pc.Add(p);
});
map.GetDoubleClick()
.Subscribe(next =>
{
ptsSubject.OnNext(pc);
pc = new ESRI.ArcGIS.Client.Geometry.PointCollection();
});
KeyValuePair<IObservable<MapPoint>, IObservable<ESRI.ArcGIS.Client.Geometry.PointCollection>> obs =
new KeyValuePair<IObservable<MapPoint>, IObservable<ESRI.ArcGIS.Client.Geometry.PointCollection>>
(ptObs, ptsObs);
return obs;
}
另外,我不太确定 Hide() 是做什么的。我只是在使用它,因为所有示例似乎都有 em。隐藏身份的真正含义是什么?