i am trying to implement a standard drag and drop image in wpf using Rx.
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);
});
i get the error Error Cannot convert lambda expression to type 'System.IObserver<System.Windows.Point>' because it is not a delegate type
what am i missing ?
The namespace System.Reactive.Linq
contains the static class Observable
which defines all the extension methods for common reactive combinators. It resides in System.Reactive.dll
The extension methods for IObservable<T>.Subscribe
such as Subscribe(onNext)
, Subscribe(onNext, onError)
are however defined in mscorlib
in the static class System.ObservableExtensions
.
tl;dr:
System.Reactive.Linq
= using System.Reactive.Linq;
System
= using System;