public TodoApp() { _todoItems = new ObservableCollection <TodoItem>(); AllTodoItems = new ReadOnlyObservableCollection <TodoItem>(_todoItems); ActiveTodoItems = AllTodoItems.ToFilteredReadOnlyObservableCollection(x => !x.Completed.Value).AddTo(_disposables); CompletedTodoitems = AllTodoItems.ToFilteredReadOnlyObservableCollection(x => x.Completed.Value).AddTo(_disposables); IsCompletedAllItems = AllTodoItems.ObserveElementProperty(x => x.Completed) .ToUnit() .Merge(AllTodoItems.CollectionChangedAsObservable().ToUnit()) .Throttle(TimeSpan.FromMilliseconds(10)) .Select(_ => AllTodoItems.Count != 0 && AllTodoItems.All(x => x.Completed.Value)) .ToReadOnlyReactivePropertySlim() .AddTo(_disposables); }
/// <summary> /// Returns if the whole context is valid checking all the validations. /// </summary> /// <returns>Returns true if the <see cref="ValidationContext"/> is valid, otherwise false.</returns> public bool GetIsValid() { return(_validations.Count == 0 || _validations.All(v => v.IsValid)); }
public BoxImportSchemeViewModel() { _boardsSource = new SourceList <BoardImportSchemeViewModel>(); _columnsSource = new SourceList <ColumnImportSchemeViewModel>(); _rowsSource = new SourceList <RowImportSchemeViewModel>(); var boardsPublish = _boardsSource.Connect() .ObserveOnDispatcher() .Publish(); boardsPublish .Count() .Subscribe(x => HasBoards = x > 0); boardsPublish .Bind(out _boards) .Subscribe(); boardsPublish .WhenPropertyChanged(x => x.IsSelected) .Subscribe(x => IsAllBoardsSelected = _boards.All(b => b.IsSelected) ? true : _boards.Any(b => b.IsSelected) ? (bool?)null : false); boardsPublish.Connect(); var selectedBoardChanged = this.WhenAnyValue(x => x.SelectedBoard).Publish(); var columnsPublish = _columnsSource.Connect() .Filter(selectedBoardChanged.Select(CreateColumnPredicate)) .ObserveOnDispatcher() .Publish(); columnsPublish .Count() .Subscribe(x => HasColumns = x > 0); columnsPublish .Bind(out _columns) .Subscribe(); columnsPublish .WhenPropertyChanged(x => x.IsSelected) .Subscribe(x => IsAllColumnsSelected = _columns.All(c => c.IsSelected) ? true : _columns.Any(c => c.IsSelected) ? (bool?)null : false); columnsPublish.Connect(); var rowsPublish = _rowsSource.Connect() .Filter(selectedBoardChanged.Select(CreateRowPredicate)) .ObserveOnDispatcher() .Publish(); rowsPublish .Count() .Subscribe(x => HasRows = x > 0); rowsPublish .Bind(out _rows) .Subscribe(); rowsPublish .WhenPropertyChanged(x => x.IsSelected) .Subscribe(x => IsAllRowsSelected = _rows.All(r => r.IsSelected) ? true : _rows.Any(r => r.IsSelected) ? (bool?)null : false); rowsPublish.Connect(); selectedBoardChanged.Connect(); AllBoardsSelectionCommand = ReactiveCommand.Create <bool?>(x => { foreach (var board in _boards) { board.IsSelected = board.IsEnabled && x.HasValue && x.Value; } }); AllColumnsSelectionCommand = ReactiveCommand.Create <bool?>(x => { foreach (var column in _columns) { column.IsSelected = x.HasValue && x.Value; } }); AllRowsSelectionCommand = ReactiveCommand.Create <bool?>(x => { foreach (var row in _rows) { row.IsSelected = x.HasValue && x.Value; } }); }
/// <summary> /// Returns if the whole context is valid checking all the validations. /// </summary> /// <returns>Returns true if the <see cref="ValidationContext"/> is valid, otherwise false.</returns> public bool GetIsValid() => _validations.Count == 0 || _validations.All(v => v.IsValid);
public SeasonFormViewModel( Season season, SeriesFormViewModel parent, IObservable <int> maxSequenceNumber, ResourceManager?resourceManager = null, IScheduler?scheduler = null) : base(parent, maxSequenceNumber, resourceManager, scheduler) { this.Season = season; var canDeletePeriod = this.periodsSource.Connect() .Count() .Select(count => count > MinPeriodCount); this.periodsSource.Connect() .Sort(SortExpressionComparer <Period> .Ascending(period => period.StartYear) .ThenByAscending(period => period.StartMonth) .ThenByAscending(period => period.EndYear) .ThenByAscending(period => period.EndMonth)) .Transform(period => this.CreatePeriodForm(period, canDeletePeriod)) .Bind(out this.periods) .DisposeMany() .Subscribe(); this.CopyProperties(); this.ChannelRule = this.ValidationRule( vm => vm.Channel, channel => !String.IsNullOrWhiteSpace(channel), "ChannelEmpty"); this.PeriodsNonOverlapping = this.periods.ToObservableChangeSet() .AutoRefreshOnObservable(pvm => pvm.Changed) .Select(_ => this.AreAllPeriodsNonOverlapping()); this.WhenAnyValue(vm => vm.CurrentPosterIndex) .Select(index => this.Season.Periods[index].PosterUrl) .BindTo(this, vm => vm.CurrentPosterUrl); var canAddPeriod = this.Periods.ToObservableChangeSet() .AutoRefreshOnObservable(period => period.Valid) .ToCollection() .Select(periods => periods.Count < MaxPeriodCount && periods.All(period => !period.HasErrors)) .CombineLatest(this.PeriodsNonOverlapping, (a, b) => a && b); this.AddPeriod = ReactiveCommand.Create(this.OnAddPeriod, canAddPeriod); var canSwitchToNextPoster = this.WhenAnyValue(vm => vm.CurrentPosterIndex) .Merge(this.Save.Select(_ => this.CurrentPosterIndex)) .Select(index => index != this.Season.Periods.Count - 1 && this.Season.Periods.Skip(index + 1).Any(period => period.PosterUrl != null)); var canSwitchToPreviousPoster = this.WhenAnyValue(vm => vm.CurrentPosterIndex) .Merge(this.Save.Select(_ => this.CurrentPosterIndex)) .Select(index => index != 0 && this.Season.Periods.Take(index).Any(period => period.PosterUrl != null)); this.SwitchToNextPoster = ReactiveCommand.Create( () => this.SetCurrentPosterIndex(index => index + 1), canSwitchToNextPoster); this.SwitchToPreviousPoster = ReactiveCommand.Create( () => this.SetCurrentPosterIndex(index => index - 1), canSwitchToPreviousPoster); this.Save.Discard() .Merge(this.GoToSeries.Discard()) .Delay(TimeSpan.FromMilliseconds(500), this.Scheduler) .Subscribe(() => this.CurrentPosterIndex = 0); this.CanAlwaysDelete(); this.EnableChangeTracking(); }