Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is the reference to IObservable

The following is not compiling on VS2010, SL5 and Reactive Extensions version 1.1.10605.1(2011-06-05).

'System.Collections.Generic.IEnumerable' does not contain a definition for 'ToObservable' and no extension method 'ToObservable' accepting a first argument of type 'System.Collections.Generic.IEnumerable' could be found (are you missing a using directive or an assembly reference?)

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));
    }
}
like image 381
Picflight Avatar asked Dec 30 '25 02:12

Picflight


2 Answers

Try adding 'using System.Reactive.Linq' ?

like image 128
Lugoues Avatar answered Dec 31 '25 15:12

Lugoues


Just in case anyone is interesting this is now deprecaited and is System.Observable namespace

like image 30
Rhys Avatar answered Dec 31 '25 16:12

Rhys



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!