コード例 #1
0
        public PhotoViewModel(IRouter router = null, IPhotosService service = null) : base(router)
        {
            Service = service ?? Locator.Current.GetService <IPhotosService>();
            var canLoadData = this.WhenAnyValue(vm => vm.Photo)
                              .Select(p => p != null);

            LoadPhotoData = ReactiveCommand.CreateAsyncTask(canLoadData, async o => await LoadPhotoDataImpl());
            photo         = OnActivated.Select(p => p.Photo)
                            .ToProperty(this, vm => vm.Photo);
            photoData = LoadPhotoData
                        .ObserveOn(RxApp.MainThreadScheduler)
                        .ToProperty(this, vm => vm.PhotoData);
            isLoading = LoadPhotoData.IsExecuting
                        .ObserveOn(RxApp.MainThreadScheduler)
                        .ToProperty(this, vm => vm.IsLoading);
            this.WhenAnyValue(vm => vm.Photo)
            .InvokeCommand(this, vm => vm.LoadPhotoData);
        }