我正在尝试使用BoundItemUpdtedHandler创建可观察的流,这是使用BoundItemUpdated事件的。
Base有两个子类,它们为网格设置数据源,在基类中,如果引发BoundItemUpdate,我将尝试创建一个流。
public delegate void BoundItemUpdatedHandler<T>(T boundItem, IEnumerable<string> properties) where T : IBoundItem;
public class BindingList<T> : BindingList<T> where T : IBoundItem
{
..
public event BoundItemUpdatedHandler<T> BoundItemUpdated;
}
public class Positions: Base
{
var datasource = new BindingList<PositionDTO>();
_grid.Datasource = datasource;
}
public class Orders: Base
{
var datasource = new BindingList<OrderDTO>();
_grid.DataSource = datasource
}
public class Base
{
public IObservable<Stream> GetStream
{
// How do I create stream using _grid? and event pattern?
}
}发布于 2013-09-28 03:40:22
我不明白你到底需要什么,这将是这条溪流的源头,从它将使用的地方,你将如何提高它?
要操作事件,理想的做法是遵循EventHandler标准:
http://msdn.microsoft.com/en-us/library/system.eventhandler.aspx ( Rx更容易使用,使用其他类型的Rx委托创建订阅要复杂一些)
但是如果您需要订阅一个具有BoundItemUpdatedHandler<T>类型的事件,您可以在下面完成它(这只是一个例子).
[TestMethod]
public void CustomEventWithRx()
{
var sx =
Observable.FromEvent(
new Func<Action<Tuple<IBoundItem, IEnumerable<string>>>, BoundItemUpdatedHandler<IBoundItem>>(
source => new BoundItemUpdatedHandler<IBoundItem>((s, e) => source(Tuple.Create(s, e)))),
add => this.CustomHandler += add,
rem => this.CustomHandler -= rem);
sx.Select((item,index) => new { item,index}).Subscribe(next => Trace.WriteLine(next.index));
OnCustomHandler(null, null);
}
public event BoundItemUpdatedHandler<IBoundItem> CustomHandler;
protected virtual void OnCustomHandler(IBoundItem bounditem, IEnumerable<string> properties)
{
BoundItemUpdatedHandler<IBoundItem> handler = CustomHandler;
if (handler != null) handler(bounditem, properties);
}
public delegate void BoundItemUpdatedHandler<T>(T boundItem, IEnumerable<string> properties) where T : IBoundItem;https://stackoverflow.com/questions/19059673
复制相似问题