public PhotoListViewModel(IRouter router = null, IPhotosService service = null) : base(router) { Service = service ?? Locator.Current.GetService <IPhotosService>(); var canLoad = Resumed.FirstAsync().Select(r => r?.LoadedPhotos == null); LoadPhotos = ReactiveCommand.CreateAsyncTask(canLoad, async o => await Service.GetPhotosAsync()); var canLoadData = this.WhenAnyValue(vm => vm.LoadedPhotos) .Select(p => p != null); LoadPhotoData = ReactiveCommand.CreateAsyncTask(canLoadData, async o => await LoadPhotoDataImpl()); Share = ReactiveCommand.CreateAsyncTask(async o => await ShareImpl()); ShowPhoto = ReactiveCommand.CreateAsyncTask(async p => await ShowPhotoImpl((int)p)); loadedPhotos = Resumed.Select(state => state?.LoadedPhotos).Merge(LoadPhotos) .ObserveOn(RxApp.MainThreadScheduler) .ToProperty(this, vm => vm.LoadedPhotos, new Photo[0]); loadedPhotoBytes = LoadPhotoData .ObserveOn(RxApp.MainThreadScheduler) .ToProperty(this, vm => vm.LoadedPhotoData); isLoading = LoadPhotos.IsExecuting.CombineLatest(LoadPhotoData.IsExecuting, (l, ld) => l || ld) .DistinctUntilChanged() .ObserveOn(RxApp.MainThreadScheduler) .ToProperty(this, vm => vm.IsLoading); this.WhenAnyValue(vm => vm.LoadedPhotos) .InvokeCommand(this, vm => vm.LoadPhotoData); }