示例#1
0
        public MainViewModel()
        {
            RestartCommand = new UtilityWpf.RelayCommand(() => _itemsCount.OnNext(5));

            var dis = Application.Current.Dispatcher;
            var x   = new System.Reactive.Concurrency.DispatcherScheduler(dis);

            GetNewItems(_itemsCount).Switch().ObserveOn(x).Subscribe(_ =>
            {
                Application.Current.Dispatcher.Invoke(() =>
                {
                    NewItem = _;
                    OnPropertyChanged(nameof(NewItem));
                });
            });

            RestartCommand.Execute(5);
        }
        public MultiSelectTreeView()
        {
            // ItemTemplateSelector =new PropertyDataTemplateSelector();

            var dispatcher = Application.Current.Dispatcher;
            var UI         = new System.Reactive.Concurrency.DispatcherScheduler(dispatcher);

            var sets = Observable.FromEventPattern <RoutedEventHandler, RoutedEventArgs>(h => Loaded += h, h => Loaded -= h).Select(_ => 0)
                       .Take(1)
                       .CombineLatest(ChildrenPathSubject.StartWith(Children).DistinctUntilChanged(),
                                      ItemsSourceSubject.DistinctUntilChanged(),
                                      (a, children, itemsource) => new { children, itemsource })
                       //.CombineLatest(KeySubject.StartWith("Key").DistinctUntilChanged(), (cp, key) => new { cp, key })
                       //.CombineLatest(CheckSubject.StartWith(Check).DistinctUntilChanged(), (ci, check) => new { check,ci })
                       .Select(init => React(/*init.a.key,*/ init.children, init.itemsource, CheckSubject.StartWith(Check).DistinctUntilChanged(), UI, dispatcher))
                       .Subscribe(_ =>
            {
                Dispatcher.InvokeAsync(() => { ItemsSource = _.Items; }, System.Windows.Threading.DispatcherPriority.Background, default);
            });
        }
示例#3
0
        public MultiSelectTreeView()
        {
            // ItemTemplateSelector =new PropertyDataTemplateSelector();
            Uri resourceLocater = new Uri("/UtilityWpf.View;component/Themes/MultiSelectTreeView.xaml", System.UriKind.Relative);
            ResourceDictionary resourceDictionary = (ResourceDictionary)Application.LoadComponent(resourceLocater);

            Style = resourceDictionary["MultiSelectTreeViewControlStyle"] as Style;

            var dispatcher = Application.Current.Dispatcher;
            var UI         = new System.Reactive.Concurrency.DispatcherScheduler(dispatcher);

            var sets = Observable.FromEventPattern <RoutedEventHandler, RoutedEventArgs>(h => this.Loaded += h, h => this.Loaded -= h).Select(_ => 0)
                       .Take(1)
                       .CombineLatest(ChildrenPathSubject.StartWith(Children).DistinctUntilChanged(),
                                      ItemsSourceSubject.DistinctUntilChanged(),
                                      (a, children, itemsource) => new { children, itemsource })
                       //.CombineLatest(KeySubject.StartWith("Key").DistinctUntilChanged(), (cp, key) => new { cp, key })
                       //.CombineLatest(CheckSubject.StartWith(Check).DistinctUntilChanged(), (ci, check) => new { check,ci })
                       .Select(init => React(/*init.a.key,*/ init.children, init.itemsource, CheckSubject.StartWith(Check).DistinctUntilChanged(), UI, dispatcher))
                       .Subscribe(_ =>
            {
                this.Dispatcher.InvokeAsync(() => { ItemsSource = _.Items; }, System.Windows.Threading.DispatcherPriority.Background, default(System.Threading.CancellationToken));
            });
        }
示例#4
0
 public static System.IObservable <TSource> SubscribeOn <TSource>(this System.IObservable <TSource> source, System.Reactive.Concurrency.DispatcherScheduler scheduler)
 {
     throw null;
 }
示例#5
0
        public virtual ViewModel.InteractiveCollectionViewModel <object, IConvertible> React(/*string key,*/ string childrenpath, IEnumerable enumerable, IObservable <bool> ischecked, System.Reactive.Concurrency.DispatcherScheduler UI, System.Windows.Threading.Dispatcher dispatcher)
        {
            var sx = ObservableChangeSet.Create <object, IConvertible>(cache =>
            {
                foreach (var val in enumerable)
                {
                    cache.AddOrUpdate(val);
                }
                return(System.Reactive.Disposables.Disposable.Empty);
            }, GetKey);

            var kx = new ViewModel.InteractiveCollectionViewModel <object, IConvertible>(sx, ChildrenPath, ischecked, ExpandSubject.StartWith(Expand).DistinctUntilChanged(), UI, dispatcher);

            kx.GetChecked();
            kx.GetSelectedItem(ischecked).Subscribe(_ =>
            {
                this.Dispatcher.InvokeAsync(() => SelectedItem = _, System.Windows.Threading.DispatcherPriority.Background, default(System.Threading.CancellationToken));
            });
            kx.GetCheckedChildItems(ischecked, childrenpath).Subscribe(_ =>
            {
                this.Dispatcher.InvokeAsync(() => CheckedItems = _, System.Windows.Threading.DispatcherPriority.Background, default(System.Threading.CancellationToken));
            });

            AllCheckedItems = kx.@checked;

            //kx.GetSelected().WithLatestFrom(ischecked,(a,b)=>new { a, b }).Subscribe(_=>
            //{
            //    if (@checked.Contains(_) || _.b==false)
            //    {
            //        this.Dispatcher.InvokeAsync(() => SelectedItem = _.a, System.Windows.Threading.DispatcherPriority.Background, default(System.Threading.CancellationToken));
            //        this.Dispatcher.InvokeAsync(() => CheckedItems = ReflectionHelper.RecursivePropValues(_.a, childrenpath).Cast<object>().Where(a => @checked.Contains(a)).ToList(), System.Windows.Threading.DispatcherPriority.Background, default(System.Threading.CancellationToken));
            //    }
            //});

            //kx.ChildSubject.Where(_=>_.Value.Interaction==Interaction.Select &&((int) _.Value.Value)>0).WithLatestFrom(ischecked, (a, b) => new { a, b }).Subscribe(_ =>
            //{
            //    if (@checked.Contains(_.a.Key) || _.b == false)
            //    {
            //        this.Dispatcher.InvokeAsync(() => SelectedItem = _.a.Key, System.Windows.Threading.DispatcherPriority.Background, default(System.Threading.CancellationToken));
            //        this.Dispatcher.InvokeAsync(() => CheckedItems = ReflectionHelper.RecursivePropValues(_.a.Key, childrenpath).Cast<object>().Where(a => @checked.Contains(a)).ToList(), System.Windows.Threading.DispatcherPriority.Background, default(System.Threading.CancellationToken));
            //    }
            //});

            //kx.ChildSubject.Where(_ => _.Value.Interaction == Interaction.Check).Subscribe(_ =>
            //{
            //    if (!((bool)_.Value.Value))
            //        if (@checked.Contains(_.Key))
            //        {
            //            @checked.Remove(_.Key);
            //            this.Dispatcher.InvokeAsync(() => SelectedItem = null, System.Windows.Threading.DispatcherPriority.Background, default(System.Threading.CancellationToken));
            //            this.Dispatcher.InvokeAsync(() => CheckedItems = null, System.Windows.Threading.DispatcherPriority.Background, default(System.Threading.CancellationToken));
            //        }

            //   else if (((bool)_.Value.Value))
            //            if (@unchecked.Contains(_.Key))
            //            {
            //                @unchecked.Remove(_.Key);
            //                this.Dispatcher.InvokeAsync(() => SelectedItem = _.Key, System.Windows.Threading.DispatcherPriority.Background, default(System.Threading.CancellationToken));
            //                this.Dispatcher.InvokeAsync(() => CheckedItems = ReflectionHelper.RecursivePropValues(_.Key, childrenpath).Cast<object>().Where(a => @checked.Contains(a)).ToList(), System.Windows.Threading.DispatcherPriority.Background, default(System.Threading.CancellationToken));
            //            }

            //});

            //kx.DoubleClicked.Subscribe(_ =>
            //{
            //    this.Dispatcher.InvokeAsync(() => DoubleClickedItem = _, System.Windows.Threading.DispatcherPriority.Background, default(System.Threading.CancellationToken));
            //});

            //SelectedItemSubject.Subscribe(_ =>

            //kx.Deleted.Subscribe(_ =>
            //{
            //    this.Dispatcher.InvokeAsync(() => Deleted = _, System.Windows.Threading.DispatcherPriority.Background, default(System.Threading.CancellationToken));
            //});
            return(kx);
        }
 public static IObservable <ViewModel.InteractiveCollectionViewModel <T, object> > Build <T>(IObservable <Func <T, object> > getkeys, IObservable <IEnumerable <T> > elems, IObservable <IFilter> filter, IObservable <T> DeletedSubject, IObservable <object> ClearedSubject, System.Reactive.Concurrency.DispatcherScheduler UI)
 {
     return(getkeys?.Select(_ =>
     {
         return Build <T>(_, elems, filter, DeletedSubject, ClearedSubject, UI);
     }));
 }
        public static ViewModel.InteractiveCollectionViewModel <T, object> Build <T>(Func <T, object> getkey, IObservable <IEnumerable <T> > elems, IObservable <IFilter> filter, IObservable <T> DeletedSubject, IObservable <object> ClearedSubject, System.Reactive.Concurrency.DispatcherScheduler UI, IObservable <Func <T, object> > getkeys = null, bool isReadOnly = false)
        {
            var dx = Observable.Create <string>(_ => () => { });

            ViewModel.InteractiveCollectionViewModel <T, object> interactivecollection = null;
            ISubject <Exception> exs = new Subject <Exception>();
            var sx = ObservableChangeSet.Create(cache =>
            {
                var dels = DeletedSubject /*.WithLatestFrom(RemoveSubject.StartWith(Remove).DistinctUntilChanged(), (d, r) => new { d, r })*/.Subscribe(_ =>
                {
                    try
                    {
                        cache.Remove(_);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("error removing " + _.ToString() + " from cache");
                        Console.WriteLine(ex.Message);
                        exs.OnNext(ex);
                        //ArgumentNullException
                    }
                });

                ClearedSubject.Subscribe(_ => cache.Clear());

                elems.Subscribe(_ =>
                {
                    foreach (var g in _)
                    {
                        try
                        {
                            cache.AddOrUpdate(g);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("error adding " + g.ToString() + " from cache");
                            Console.WriteLine(ex);
                            exs.OnNext(ex);
                        }
                    }
                });
                return(new System.Reactive.Disposables.CompositeDisposable(dels));
            }, getkey)
                     .Filter(filter.Select(_ => { Func <T, bool> f = aa => _.Filter(aa); return(f); }).StartWith(ft));

            getkeys?.Subscribe(_ =>
            {
                sx.ChangeKey(_);
            });

            interactivecollection = new ViewModel.InteractiveCollectionViewModel <T, object>(sx, UI, DeletedSubject, _ => (IConvertible)getkey(_));

            exs.Subscribe(ex =>
                          (interactivecollection.Errors as System.Reactive.Subjects.ISubject <Exception>).OnNext(ex));

            return(interactivecollection);
        }