我尝试使用Rx在WPF应用程序中进行拖放操作,当我尝试订阅一个EntryPointNotFindException时抛出....有人可以帮我这个吗?
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);
});
}
}
编辑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
答案 0 :(得分:0)
确保您对PresentationFoundation,WindowsBase,PresentationCore和System.Xaml有所引用,您可能缺少其中一个。确保您还引用了System.Reactive.Windows.Threading.dll