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.Linqcontains the static classObservablewhich defines all the extension methods for common reactive combinators. It resides inSystem.Reactive.dllThe extension methods for
IObservable<T>.Subscribesuch asSubscribe(onNext),Subscribe(onNext, onError)are however defined inmscorlibin the static classSystem.ObservableExtensions.tl;dr:
System.Reactive.Linq=using System.Reactive.Linq;System=using System;