public CalculatorViewModel()
        {
            _reactiveHelper = new MakeObjectReactiveHelper(this);
            _cache          = new MemoizingMRUCache <int, int>((x, ctx) =>
            {
                Thread.Sleep(1000);
                // Pretend this calculation isn’t cheap
                return(x * 10);
            }, 5);

            CalculateCommand = new ReactiveAsyncCommand(this.WhenAny(x => x.Number, x => x.Value > 0));
            (CalculateCommand as ReactiveAsyncCommand).RegisterAsyncTask <object>(o =>
            {
                return(Task.Factory.StartNew(() =>
                {
                    int top;
                    bool cached = _cache.TryGet(Number, out top);
                    if (cached)
                    {
                        Result = 0;
                        Thread.Sleep(1000);
                        Result = top;
                    }
                    else
                    {
                        top = _cache.Get(Number);
                        for (int i = 0; i <= top; i++)
                        {
                            Result = i;
                            Thread.Sleep(100);
                        }
                    }
                }));
            });
        }
Beispiel #2
0
        public MainViewModel()
        {
            _reactiveHelper = new MakeObjectReactiveHelper(this);
            DisplayName     = "Caliburn.Micro works side-by-side with ReactiveUI";

            RxApp.DeferredScheduler = new DispatcherScheduler(Application.Current.Dispatcher);
            Task.Factory.StartNew(() =>
            {
                while (true)
                {
                    if (Progress == 100)
                    {
                        Progress = 0;
                    }
                    Progress++;
                    Thread.Sleep(Progress % 10 == 0 ? 2000 : 400);
                }
            });

            //Throttling the Progress property updates for the SlowProgress.
            //Two ways to observe the changes on the Progress property
            // 1:
            this.ObservableForProperty(vm => vm.Progress)
            .Throttle(TimeSpan.FromSeconds(1), RxApp.DeferredScheduler)
            .Subscribe(c => SlowProgress = Progress);
            // 2:
            this.WhenAny(vm => vm.Progress, model => true)
            .Throttle(TimeSpan.FromSeconds(1), RxApp.DeferredScheduler).
            Subscribe(c => SlowProgress2 = Progress);

            Person     = new PersonViewModel();
            Calculator = new CalculatorViewModel();
        }
        public CalculatorViewModel()
        {
            _reactiveHelper = new MakeObjectReactiveHelper(this);
            _cache = new MemoizingMRUCache<int, int>((x, ctx) =>
            {
                Thread.Sleep(1000);
                // Pretend this calculation isn’t cheap
                return x*10;
            }, 5);

            CalculateCommand = new ReactiveAsyncCommand(this.WhenAny(x => x.Number, x => x.Value > 0));
            (CalculateCommand as ReactiveAsyncCommand).RegisterAsyncTask<object>(o =>
            {
                return Task.Factory.StartNew(() =>
                {
                    int top;
                    bool cached = _cache.TryGet(    Number, out top);
                    if (cached)
                    {
                        Result = 0;
                        Thread.Sleep(1000);
                        Result = top;
                    }
                    else
                    {
                        top = _cache.Get(Number);
                        for (int i = 0; i <= top; i++)
                        {
                            Result = i;
                            Thread.Sleep(100);
                        }
                    }
                });
            });
        }
        public MainViewModel()
        {
           
            _reactiveHelper = new MakeObjectReactiveHelper(this);
            DisplayName = "Caliburn.Micro works side-by-side with ReactiveUI";

            RxApp.DeferredScheduler = new DispatcherScheduler(Application.Current.Dispatcher);
            Task.Factory.StartNew(() =>
            {
                while (true)
                {
                    if (Progress == 100)
                    {
                        Progress = 0;

                    }
                    Progress++;
                    Thread.Sleep(Progress%10 == 0 ? 2000 : 400);
                }

            });
            
            //Throttling the Progress property updates for the SlowProgress. 
            //Two ways to observe the changes on the Progress property
            // 1:
            this.ObservableForProperty(vm => vm.Progress)
                .Throttle(TimeSpan.FromSeconds(1), RxApp.DeferredScheduler)
                .Subscribe(c => SlowProgress = Progress);
            // 2:
            this.WhenAny(vm => vm.Progress, model => true)
                .Throttle(TimeSpan.FromSeconds(1), RxApp.DeferredScheduler).
                Subscribe(c => SlowProgress2 = Progress);

            Person = new PersonViewModel();
            Calculator = new CalculatorViewModel();
        }
 public NonReactiveINPCObjectMadeReactive()
 {
     _reactiveHelper = new MakeObjectReactiveHelper(this);
 }
 public NonReactiveINPCObjectMadeReactive()
 {
     _reactiveHelper = new MakeObjectReactiveHelper(this);
 }