ash*_*ina 24 wpf lambda system.reactive
我正在尝试使用Rx在wpf中实现标准的拖放图像.
var mouseDown = from evt in Observable.FromEventPattern<MouseButtonEventArgs>(image, "MouseLeftButtonDown")
select evt.EventArgs.GetPosition(image);
var mouseUp = Observable.FromEventPattern<MouseButtonEventArgs>(this, "MouseLeftButtonUp");
var mouseMove = from evt in Observable.FromEventPattern<MouseEventArgs>(this, "MouseMove")
select evt.EventArgs.GetPosition(this);
var q = from startLocation in mouseDown
from endLocation in mouseMove.TakeUntil(mouseUp)
select new Point
{
X = endLocation.X - startLocation.X,
Y = endLocation.Y - startLocation.Y
};
q.ObserveOn(SynchronizationContext.Current).Subscribe(point =>
{
Canvas.SetLeft(image, point.X);
Canvas.SetTop(image, point.Y);
});
Run Code Online (Sandbox Code Playgroud)
我收到错误错误 Cannot convert lambda expression to type 'System.IObserver<System.Windows.Point>' because it is not a delegate type
我错过了什么?
Ast*_*sti 41
命名空间System.Reactive.Linq包含静态类Observable,它定义了常见的无功组合器的所有扩展方法.它居住在System.Reactive.dll
用于扩展方法IObservable<T>.Subscribe如Subscribe(onNext),Subscribe(onNext, onError)被然而,在定义mscorlib在静态类System.ObservableExtensions.
TL;博士:
System.Reactive.Linq=using System.Reactive.Linq; System=using System;为了使这个更清晰的答案基于@Gideon Engelberths在问题中排在第5位,我错过了"使用系统"; 在我的班级使用指令:
using System.Reactive.Linq;
using System;
Run Code Online (Sandbox Code Playgroud)
然后修复了编译器问题.谢谢基甸.