public InteractiveCollectionViewModel(IEnumerable <T> enumerable, string childrenpath, IObservable <bool> ischecked, IObservable <bool> expand, System.Windows.Threading.Dispatcher dispatcher = null, Func <T, IConvertible> getkey = null, string title = null) { var xs = enumerable.Select (s => { var so = new ChildInteractiveObject <T>(s, childrenpath, ischecked, expand, getkey?.Invoke(s)); return(so); }).ToList(); foreach (var so in xs) { this.ReactToChanges(so); so.OnPropertyChangeWithSource <ChildInteractiveObject <T>, KeyValuePair <T, InteractionArgs> >(nameof(ChildInteractiveObject <T> .ChildChanged)).Subscribe(_ => { childSubject.OnNext(_.Item2); }); } items = new ReadOnlyObservableCollection <IObject <T> >(new ObservableCollection <IObject <T> >(xs)); ischecked.DelaySubscription(TimeSpan.FromSeconds(0.5)).Take(1).Subscribe(_ => { foreach (var x in xs) { x.IsChecked = _; } }); Title = title; }
public InteractiveCollectionViewModel(IObservable <IChangeSet <T, R> > observable, string childrenpath, IObservable <bool> ischecked, IObservable <bool> expand, Func <T, IConvertible>?getkey = null, string?title = null) { disposable = observable .Transform(s => { var so = new ChildInteractiveObject <T>(s, childrenpath, ischecked, expand, getkey?.Invoke(s)); so.OnPropertyChangeWithSource <ChildInteractiveObject <T>, KeyValuePair <T, InteractionArgs> >(nameof(ChildInteractiveObject <T> .ChildChanged)).Subscribe(_ => { childSubject.OnNext(_.Item2); }); this.ReactToChanges(so); return((IObject <T>)so); }) .Bind(out items) .DisposeMany() .Subscribe( _ => { foreach (var x in _.Select(a => new KeyValuePair <IObject <T>, ChangeReason>(a.Current, a.Reason))) { (Changes as Subject <KeyValuePair <IObject <T>, ChangeReason> >).OnNext(x); } }, ex => Console.WriteLine("Error in generic view model"), () => Console.WriteLine("observable completed")); ischecked.DelaySubscription(TimeSpan.FromSeconds(0.5)).Take(1).Subscribe(_ => { foreach (var x in items) { (x as ChildInteractiveObject <T>).IsChecked = _; } }); Title = title; }