2011-12-09 93 views
0

我試圖使用Rx在WPF應用程序中進行拖放操作,當我嘗試Subscrive EntryPointNotFindException時拋出....任何人都可以幫助我解決這個問題嗎?當通過IObservable訂閱事件時EntryPointNotFound

WPF應用程序代碼

<Window x:Class="RxDragDropPOC.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="MainWindow" Height="300" Width="300"> 
<Canvas Name="canvas"> 
    <TextBlock Name="textBlock" Text="Test" /> 
    <Image Canvas.Left="0" Canvas.Top="25" Height="100" Name="image" Width="100" Source="C:/Users/guilherme.dias/Desktop/images.jpg" /> 
</Canvas> 

C#代碼

public partial class MainWindow : Window 
{ 

    public MainWindow() 
    { 
     InitializeComponent(); 

     var mouseDown = from evt in Observable.FromEvent<MouseButtonEventArgs>(image, "MouseLeftButtonDown") 
         select evt.EventArgs.GetPosition(this); 
     var mouseUp = from evt in Observable.FromEvent<MouseButtonEventArgs>(image, "MouseLeftButtonUp") 
         select evt.EventArgs.GetPosition(this); 
     var mouseMove = from evt in Observable.FromEvent<MouseEventArgs>(image, "MouseMove") 
         select evt.EventArgs.GetPosition(this); 

     var q = from start in mouseDown 
       from pos in mouseMove.StartWith(start).TakeUntil(mouseUp). 
          Let(mm => mm.Zip(mm.Skip(1), (prev, cur) => 
           new { X = cur.X - prev.X, Y = cur.Y - prev.Y })) 
       select pos; 

     //THIS IS THE LINE THAT THROWS EntryPointNotFound 
     q.ObserveOnDispatcher().Subscribe(value => 
     { 
      Canvas.SetLeft(image, Canvas.GetLeft(image) + value.X); 
      Canvas.SetTop(image, Canvas.GetTop(image) + value.Y); 
     }); 
    } 
} 

EDIT 1個

異常詳細

System.EntryPointNotFoundException was caught 
Message=Entry point was not found. 
Source=mscorlib 
TypeName="" 
StackTrace: 
    at System.IObservable`1.Subscribe(IObserver`1 observer) 
    at System.ObservableExtensions.Subscribe[TSource](IObservable`1 source, Action`1 onNext, Action`1 onError, Action onCompleted) 
    at System.Linq.Observable.<>c__DisplayClass3dd`2.<Select>b__3db(IObserver`1 observer) 
    at System.Collections.Generic.AnonymousObservable`1.<>c__DisplayClass1.<Subscribe>b__0() 
    at System.Concurrency.CurrentThreadScheduler.EnsureTrampoline(Action action) 
    at System.Collections.Generic.AnonymousObservable`1.Subscribe(IObserver`1 observer) 
    at System.ObservableExtensions.Subscribe[TSource](IObservable`1 source, Action`1 onNext, Action`1 onError, Action onCompleted) 
    at System.Linq.Observable.<>c__DisplayClass3dd`2.<Select>b__3db(IObserver`1 observer) 
    at System.Collections.Generic.AnonymousObservable`1.<>c__DisplayClass1.<Subscribe>b__0() 
    at System.Concurrency.CurrentThreadScheduler.EnsureTrampoline(Action action) 
    at System.Collections.Generic.AnonymousObservable`1.Subscribe(IObserver`1 observer) 
    at System.ObservableExtensions.Subscribe[TSource](IObservable`1 source, Action`1 onNext, Action`1 onError, Action onCompleted) 
    at System.Linq.Observable.<>c__DisplayClass2e5`1.<Merge>b__2de(IObserver`1 observer) 
    at System.Collections.Generic.AnonymousObservable`1.<>c__DisplayClass1.<Subscribe>b__0() 
    at System.Concurrency.CurrentThreadScheduler.EnsureTrampoline(Action action) 
    at System.Collections.Generic.AnonymousObservable`1.Subscribe(IObserver`1 observer) 
    at System.ObservableExtensions.Subscribe[TSource](IObservable`1 source, Action`1 onNext, Action`1 onError, Action onCompleted) 
    at System.Linq.Observable.<>c__DisplayClass27b`1.<ObserveOn>b__274(IObserver`1 observer) 
    at System.Collections.Generic.AnonymousObservable`1.<>c__DisplayClass1.<Subscribe>b__0() 
    at System.Concurrency.CurrentThreadScheduler.EnsureTrampoline(Action action) 
    at System.Collections.Generic.AnonymousObservable`1.Subscribe(IObserver`1 observer) 
    at System.ObservableExtensions.Subscribe[TSource](IObservable`1 source, Action`1 onNext, Action`1 onError, Action onCompleted) 
    at System.ObservableExtensions.Subscribe[TSource](IObservable`1 source, Action`1 onNext) 
    at RxDragDropPOC.MainWindow..ctor() in C:\Semantic Framework\POC\RxDragDropPOC\RxDragDropPOC\MainWindow.xaml.cs:line 46 
+1

請提供例外的詳細信息。現在看起來你有一些編譯錯誤或錯誤的彙編引用。 –

回答

0

確保您有對PresentationFoundation,WindowsBase,PresentationCore和System.Xaml的引用,您可能會錯過其中的一個。確保你也有一個參考System.Reactive.Windows.Threading.dll

+0

我有所有的引用,但例外不斷顯示 – Guilherme