2012-02-26 6 views
14

sto provando ad implementare un'immagine drag and drop standard in wpf usando Rx.Errore Impossibile convertire l'espressione lambda in subscribe per un IObservable <Point>

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); 
      }); 

ottengo l'errore errore Cannot convert lambda expression to type 'System.IObserver<System.Windows.Point>' because it is not a delegate type

Che cosa mi manca?

+0

Il tuo codice funziona bene per me. Avete referenziato Rx-Main e Rx-WPF? – Phil

+0

sì, ho fatto riferimento entrambi. –

+0

Si prega di verificare se la piattaforma di destinazione dice .NET 4 Client Profile e se sì quindi cambiarlo in .NET 4. – Christoph

risposta

29

Il namespace System.Reactive.Linq contiene la classe statica Observable che definisce tutti i metodi di estensione per i combinatori reattivi comuni. Risiede nel System.Reactive.dll

I metodi di estensione per IObservable<T>.Subscribe come Subscribe(onNext), Subscribe(onNext, onError) sono tuttavia definite nella libreria di base nella classe statica System.ObservableExtensions.

tl; dr:

  • RX è necessario importare System.Reactive.Linq = using System.Reactive.Linq;
  • Per Iscriviti sovraccarichi è necessario importare System = using System;
2

per rendere questa una risposta più chiara basata su @Gideon Engelberths commenta il quinto in basso nella domanda mi mancava il 'using System;' utilizzando la direttiva nella mia classe:

using System.Reactive.Linq; 
using System; 

Che ha quindi risolto il problema del compilatore. Grazie a Gideon.

Problemi correlati