コード例 #1
0
        public SimpleGraphViewModel()
        {
            var observer = MementoObserver.Monitor(service);

            UndoCommand = DelegateCommand.Create()
                          .OnCanExecute(o => service.CanUndo)
                          .OnExecute(o => service.Undo())
                          .AddMonitor(observer);

            RedoCommand = DelegateCommand.Create()
                          .OnCanExecute(o => service.CanRedo)
                          .OnExecute(o => service.Redo())
                          .AddMonitor(observer);

            var person = new Person()
            {
                FirstName = "Mauro",
                LastName  = "Servienti"
            };

            var entity = new PersonViewModel();

            service.Attach(entity);

            entity.Initialize(person, false);

            Entity = entity;
        }
コード例 #2
0
        public ComplexGraphViewModel()
        {
            var observer = MementoObserver.Monitor(this.service);

            this.UndoCommand = DelegateCommand.Create()
                               .OnCanExecute(o => this.service.CanUndo)
                               .OnExecute(o => this.service.Undo())
                               .AddMonitor(observer);

            this.RedoCommand = DelegateCommand.Create()
                               .OnCanExecute(o => this.service.CanRedo)
                               .OnExecute(o => this.service.Redo())
                               .AddMonitor(observer);

            this.CreateNewAddressCommand = DelegateCommand.Create()
                                           .OnExecute(o =>
            {
                var address          = this.Entity.Addresses.AddNew();
                this.SelectedAddress = address;
            });

            this.DeleteAddressCommand = DelegateCommand.Create()
                                        .OnCanExecute(o => this.SelectedAddress != null)
                                        .OnExecute(o =>
            {
                this.SelectedAddress.Delete();
                this.SelectedAddress = this.Entity.Addresses.FirstOrDefault();
            })
                                        .AddMonitor
                                        (
                PropertyObserver.For(this)
                .Observe(v => v.SelectedAddress)
                                        );

            var person = new Person()
            {
                FirstName = "Mauro",
                LastName  = "Servienti"
            };

            person.Addresses.Add(new Address(person)
            {
                City    = "Treviglio",
                Number  = "11",
                Street  = "Where I live",
                ZipCode = "20100"
            });

            person.Addresses.Add(new Address(person)
            {
                City    = "Daolasa",
                Number  = "2",
                Street  = "Pierino",
                ZipCode = "20100"
            });

            var entity = new PersonViewModel();

            entity.Initialize(person, false);

            this.service.Attach(entity);

            this.Entity = entity;
        }