コード例 #1
0
        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 xx = enumerable.Select
                         (s =>
            {
                var so = new SEObject <T>(s, childrenpath, ischecked, expand, dispatcher, getkey?.Invoke(s));

                return((IContain <T>)so);
            }).ToList();

            foreach (var so in xx)
            {
                this.ReactToChanges((SEObject <T>)so);
                (so as SEObject <T>).OnPropertyChangeWithSource <SEObject <T>, KeyValuePair <T, InteractionArgs> >(nameof(SEObject <T> .ChildChanged)).Subscribe(_ =>
                {
                    ChildSubject.OnNext(_.Item2);
                });
            }

            _items = new ReadOnlyObservableCollection <IContain <T> >(new ObservableCollection <IContain <T> >(xx));

            ischecked.DelaySubscription(TimeSpan.FromSeconds(0.5)).Take(1).Subscribe(_ =>
            {
                foreach (var x in xx)
                {
                    (x as SEObject <T>).IsChecked = _;
                }
            });

            Title = title;
        }
コード例 #2
0
        //((System.Reactive.Subjects.ISubject<KeyValuePair<object, InteractionArgs>>) interactivecollection.Interactions).OnNext(new KeyValuePair<object, InteractionArgs>(_.d, new InteractionArgs { Interaction = Interaction.Include, Value = false }));

        public InteractiveCollectionViewModel(IObservable <IChangeSet <T, R> > observable, string childrenpath, IObservable <bool> ischecked, IObservable <bool> expand, IScheduler scheduler, System.Windows.Threading.Dispatcher dispatcher, Func <T, IConvertible> getkey = null, string title = null)
        {
            disposable = observable
                         .ObserveOn(scheduler)
                         .Transform(s =>
            {
                var so = new SEObject <T>(s, childrenpath, ischecked, expand, dispatcher, getkey?.Invoke(s));

                so.OnPropertyChangeWithSource <SEObject <T>, KeyValuePair <T, InteractionArgs> >(nameof(SEObject <T> .ChildChanged)).Subscribe(_ =>
                {
                    ChildSubject.OnNext(_.Item2);
                });

                this.ReactToChanges(so);
                return((IContain <T>)so);
            })
                         .Bind(out _items)
                         .DisposeMany()
                         .Subscribe(
                _ =>
            {
                foreach (var x in _.Select(a => new KeyValuePair <IContain <T>, ChangeReason>(a.Current, a.Reason)))
                {
                    (Changes as Subject <KeyValuePair <IContain <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 SEObject <T>).IsChecked = _;
                }
            });

            Title = title;
        }