Exemplo n.º 1
0
        public SessionViewModel(SessionModel model ,IPersonFactory<Person> personFactory)
        {
            _model = model.ThrowIfNull("model");
            _personFactory = personFactory.ThrowIfNull("personFactory");

            AddNewPersonCommand = new ReactiveCommand();
            AddNewPersonCommand.Subscribe(dontcare =>
                _model.Participants.Add(_personFactory.GetNewPerson(Participants.Count)));

            Participants = _model.Participants
                                    .CreateDerivedCollection(x => new ParticipantViewModel(x));

            Participants.ChangeTrackingEnabled = true;

            var deleteCanExecute = Observable.Merge(Participants.ItemChanged
                                                 .Select(_ => Participants.Any(p => p.IsSelected)),
                                             Participants.CollectionCountChanged
                                             .Select(_ => Participants.Any(p=> p.IsSelected)));

            DeleteSelectedCommand = new ReactiveCommand
                (
                       deleteCanExecute
                );
            DeleteSelectedCommand.Subscribe(
                x =>
                    {
                        RemoveSelected();
                    }
                );

            AddNewPersonCommand.Execute(null);
        }