Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error Cannot convert lambda expression in subscribe for an IObservable<Point>

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 ?

like image 880
ashutosh raina Avatar asked Feb 26 '12 14:02

ashutosh raina


1 Answers

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:

  • For Rx/Observable extension methods you need to import System.Reactive.Linq = using System.Reactive.Linq;
  • For Subscribe overloads you need to import System = using System;
like image 131
Asti Avatar answered Sep 20 '22 04:09

Asti