コード例 #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(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);

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

            DeleteAddressCommand = DelegateCommand.Create()
                                   .OnCanExecute(o => SelectedAddress != null)
                                   .OnExecute(o =>
            {
                SelectedAddress.Delete();
                SelectedAddress = 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);

            service.Attach(entity);

            Entity = entity;
        }