Skip to content

Subscribe to all ReactiveProperty inside a ObservableList? #312

Open
@devcube9

Description

@devcube9

Hi

I haven't been able to find a solution for this problem, but I am encountering this frequent enough that I thought it might be a good idea to ask here:

public class Element {
    public ReactiveProperty<bool> Completed = new();
}

public class List {
    public ObservableList<Element> Elements = new();
    public ReadOnlyReactiveProperty<bool> AllCompleted = ???
}

How do I complete AllCompleted here so that it listens to all Element.Completed in Elements list? The main problem is that Elements list is dynamic and can add/remove elements.

In addition, I stumbled upon this observable to convert CollectionChanged to an observable in UniRx here

Observable.FromEvent<NotifyCollectionChangedEventHandler<Element>, NotifyCollectionChangedEventArgs<Element>>(
                h => (sender, e) => h(e),
                h => source.CollectionChanged += h,
                h => source.CollectionChanged -= h);

but I couldn't get it to work in ObservableCollection because of this error:

The type 'NotifyCollectionChangedEventArgs' may not be a ref struct or a type parameter allowing ref structs in order to use it as parameter 'T' in the generic type or method 'Observable.FromEvent<TDelegate, T>(Func<Action, TDelegate>, Action, Action, CancellationToken)'CS9244

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions