예제 #1
0
파일: Program.cs 프로젝트: lycilph/Projects
        static void Main(string[] args)
        {
            var m = new Model();
            var vm = new ViewModel(m);

            vm.PropertyChanged += (sender, eventArgs) =>
                                      {
                                          if (eventArgs.PropertyName == "AllCategories")
                                          {
                                              foreach (var category in vm.AllCategories)
                                                  Console.WriteLine(category);
                                          }
                                          else if (eventArgs.PropertyName == "AllCategoriesCount")
                                              Console.WriteLine("(VM) New count " + vm.AllCategoriesCount);
                                      };
            vm.WrappedModel.PropertyChanged += (sender, eventArgs) =>
                                                   {
                                                       if (eventArgs.PropertyName == "CategoriesCount")
                                                           Console.WriteLine("(M) New count " + vm.WrappedModel.CategoriesCount);
                                                   };

            vm.WrappedModel.Categories.Add("Item 1");
            vm.WrappedModel.Categories.Add("Item 2");
            vm.WrappedModel.Categories.Add("Item 3");
            vm.WrappedModel.Categories.Add("Item 4");
            vm.WrappedModel.Categories.Add("Item 5");

            Console.WriteLine("Press any key to continues...");
            Console.ReadKey();
        }
예제 #2
0
        public ViewModel(Model model)
        {
            WrappedModel = model;

            AddDependency(() => WrappedModel.Categories, () => AllCategories);
            AddDependency(() => AllCategories, () => AllCategoriesCount);
        }
예제 #3
0
 public ViewModel(Model m)
 {
     WrappedModel = m;
 }