2011-06-12 46 views
2

以下不在VS2010,SL5和Reactive Extensions版本1.1.10605.1(2011-06-05)上進行編譯。對IObservable的引用在哪裏

'System.Collections.Generic.IEnumerable'不包含'ToObservable'的定義,並且沒有找到接受'System.Collections.Generic.IEnumerable'類型的第一個參數的擴展方法'ToObservable'缺少使用指令或組件參考?)

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Net; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Documents; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Animation; 
using System.Windows.Shapes; 

public partial class MainPage : UserControl 
{ 
    public MainPage() 
    { 
     InitializeComponent(); 
} 


private void ButtonNormal_Click(object sender, RoutedEventArgs e) 
    { 
     //MyList.ItemsSource = GetModel(); 
     var items = new System.Collections.ObjectModel.ObservableCollection<string>(); 
     MyList.ItemsSource = items; 
     foreach (string item in GetModel()) 
      items.Add(item); 
    } 

    private void ButtonRx_Click(object sender, RoutedEventArgs e) 
    { 
     var items = new System.Collections.ObjectModel.ObservableCollection<string>(); 
     MyList.ItemsSource = items; 

     IObservable<string> observable = GetModel() 
      .ToObservable(System.Concurrency.Scheduler.NewThread); 
     observable.ObserveOnDispatcher().Subscribe(item => items.Add(item)); 
    } 
} 
+0

我有對mscorlib和system.reactive的引用。在添加參考窗口中提供的參考列表中找不到System.Observable。 – Picflight 2011-06-12 18:30:23

回答

6

嘗試添加'using System.Reactive.Linq'?

+0

這看起來關心ToObservable。命名空間'System'中不存在類型或名稱空間名稱'Concurrency'(您是否缺少程序集引用?)這看起來像是一個Phone dll? – Picflight 2011-06-13 14:21:55

+1

併發處於「System.Reactive.Concurrency」中。 – Lugoues 2011-06-14 02:23:23

0

也許您沒有參考/使用到反應性組件?
你引用了mscorlib.dll嗎?
另外它可能是你需要包含System.Observable.dll到你的項目。

2

只是爲了防止任何人感興趣,現在已降級並且是System.Observable命名空間