Observable.Take(Observable<int>) ?

40 views
Skip to first unread message

Valdimar Kristjánsson

unread,
Sep 9, 2015, 10:16:37 AM9/9/15
to ReactiveUI mailing list
Hi,

I have a collection and a property indicating how many items should be visible to the user (the user can change the count via the ui).

public class TestClass
{
    int _VisibleItems = 0; 
    public int VisibleItems
    {
        get {return _VisibleItems; }
        set { this.RaiseAndSetIfChanged(ref _VisibleItems, value);}
    }

    public IReactiveDerivedList<Row> Rows {get;set;}

    public TestClass()
    {
        Rows = _sourceCollection.ToObservable().Take(VisibleItems).CreateCollection();
    }
}


The problem is that Take completes on creating the collection so that no updates are visible when the user changes the VisibleItems (it seems that making changes to the sourceCollection doesn't even update the derived collection either.

I tried a different method for it as well:

public class TestClass
{
    int _VisibleItems = 0; 
    public int VisibleItems
    {
        get {return _VisibleItems; }
        set { this.RaiseAndSetIfChanged(ref _VisibleItems, value);}
    }

    public IReactiveDerivedList<Row> Rows {get;set;}

    public TestClass()
    {
        Rows = Book.Orders.Orders.CreateDerivedCollection(x => x,
                                                                                               x => _sourceCollection.IndexOf(x) < VisibleChildRows,
                                                                                               signalReset: this.WhenAnyValue(x => x.VisibleChildRows),
                                                                                               scheduler: RxApp.MainThreadScheduler);

    }
}

But then I started to get a lot of Collection was modified errors without a direct stack trace to where the collection was being modified (I guess it's the IndexOf)

Any ideas on how to do this efficiently?

Reply all
Reply to author
Forward
0 new messages