Exemple #1
0
        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();
        }
Exemple #2
0
        public ViewModel(Model model)
        {
            WrappedModel = model;

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