Ejemplo n.º 1
0
        public MainWindow() :
            base(Gtk.WindowType.Toplevel)
        {
            this.Build();

            //Set the ViewModels for each widget
            var crownTestsViewModel = new CrownTestsViewModel();

            BindingEngine.SetViewModel(this, crownTestsViewModel);
            //txtTestFolder and txtCrownTestsExe automatically inherit the view model of the MainWindow because it has not been not specified

            //Create and Apply templates for each widget
            Templating.ApplyTemplate(twTests,
                                     new TreeViewTemplate()
                                     .AddColumn("Name", new Gtk.CellRendererText())
                                     .AddColumn("State", new Gtk.CellRendererText())
                                     .AddRowTemplate(TreeViewRowTemplate.Create(typeof(TestCategory))
                                                     .SetBinding("Name", "Name"))
                                     .AddRowTemplate(TreeViewRowTemplate.Create(typeof(Test))
                                                     .SetBinding("Name", "Name")
                                                     .SetBinding("State", "LastResult")));

            Templating.ApplyTemplate(txtTestFolder,
                                     new EntryTemplate().SetTextBinding("TestFolder"));

            Templating.ApplyTemplate(txtCrownTestsExe,
                                     new EntryTemplate().SetTextBinding("CrownTestsExe"));

            LoadTestsData();
        }
Ejemplo n.º 2
0
        public void Test_BindingEngine_ClearBinding_Object()
        {
            var viewModel  = new TestViewModel();
            var viewModel2 = new TestViewModel2();

            BindingEngine.SetPropertyBinding(viewModel2, "Name", viewModel, "Name")
            .SetMode(BindMode.TwoWay);

            viewModel.Name = Name1;
            Assert.AreEqual(viewModel2.Name, Name1);

            BindingEngine.SetPropertyBinding(viewModel2, "Age", viewModel, "Age")
            .SetMode(BindMode.TwoWay);

            BindingEngine.ClearBinding(new TestViewModel());

            viewModel.Age = 2;
            Assert.AreEqual(viewModel2.Age, 2);

            BindingEngine.ClearBinding(viewModel2);

            viewModel.Name = Name2;
            Assert.AreNotEqual(viewModel2.Name, Name2);
            viewModel.Age = 3;
            Assert.AreNotEqual(viewModel2.Age, 3);
        }
Ejemplo n.º 3
0
        public void Test_BindingEngine_ClearBinding_Object_Property_Expression()
        {
            var viewModel   = new TestViewModel();
            var viewModel2  = new TestViewModel2();
            var viewModel22 = new TestViewModel2();

            BindingEngine.SetPropertyBinding(viewModel, "Age", viewModel2, "Age");
            BindingEngine.SetPropertyBinding(viewModel, "Age", viewModel22, "Age");

            viewModel2.Age = 2;
            Assert.AreEqual(viewModel.Age, 2);
            viewModel22.Age = 3;
            Assert.AreEqual(viewModel.Age, 3);

            BindingEngine.ClearBinding(viewModel, model => model.Age);

            viewModel2.Age = 4;
            Assert.AreNotEqual(viewModel.Age, 4);
            viewModel22.Age = 5;
            Assert.AreNotEqual(viewModel.Age, 5);

            BindingEngine.SetPropertyBinding(viewModel, "Age", viewModel2, "Age");
            Assert.AreEqual(viewModel.Age, 4);
            BindingEngine.SetPropertyBinding(viewModel, "Age", viewModel22, "Age");
            Assert.AreEqual(viewModel.Age, 5);
        }
Ejemplo n.º 4
0
        public void Test_BindingEngine_NotifyBinding()
        {
            var viewModel    = new TestViewModel();
            var view         = new TestView();
            int changedCount = 0;

            BindingEngine.SetNotifyBinding(viewModel, o => o.Age, view, null)
            .Initialize <WeakNotifyBinding>()
            .AttachSourceEvent("TestViewEvent")
            .OfType <WeakNotifyBinding>()
            .SetSourceChanged <WeakNotifyBinding>((source, args) => { changedCount++; });

            Assert.AreEqual(0, changedCount);

            view.RaiseTestViewEvent();

            Assert.AreEqual(1, changedCount);

            BindingEngine.SetNotifyBinding(viewModel, o => o.Age, view, null)
            .Initialize <WeakNotifyBinding>()
            .AttachSourceEvent("TestViewEvent")
            .OfType <WeakNotifyBinding>()
            .SetSourceChanged <WeakNotifyBinding>((source, args) => { changedCount++; });

            view.RaiseTestViewEvent();

            Assert.AreEqual(2, changedCount);
        }
Ejemplo n.º 5
0
        public void Test_BindingEngine_CollectionBinding_Expression()
        {
            var viewModel = new TestViewModel();
            var view      = new TestView();

            BindingEngine.SetCollectionBinding(view, o => o.TestViewModelCollections, viewModel,
                                               i => i.TestViewModelCollection)
            .Initialize <WeakCollectionBinding>();

            view.TestViewModelCollections = new List <TestViewModel2>();
            var collections = new ObservableCollection <TestViewModel2>();

            viewModel.TestViewModelCollection = collections;

            var viewModel2 = new TestViewModel2();

            collections.Add(viewModel2);
            collections.Add(new TestViewModel2());

            Assert.AreEqual(2, view.TestViewModelCollections.Count);
            Assert.AreEqual(viewModel2, view.TestViewModelCollections[0]);

            collections.RemoveAt(0);
            Assert.AreEqual(1, view.TestViewModelCollections.Count);

            collections.Clear();
            Assert.AreEqual(0, view.TestViewModelCollections.Count);
        }
Ejemplo n.º 6
0
        public void SetGlobalBinding()
        {
            BindingEngine.SetPropertyBinding(this.winformBindingCbx, i => i.Checked, this, null, false)
            .SetMode(BindMode.OneWayToSource)
            .AttachTargetEvent("CheckedChanged")
            .OfType <WeakPropertyBinding>()
            .SetSourcePropertySetter((data, o) => ((MainForm)data.Source.Source).UpdateWinformBinding((bool)o))
            .Activate();

            BindingEngine.SetPropertyBinding(this.wpfBindingCbx, i => i.Checked, this, null, false)
            .SetMode(BindMode.OneWayToSource)
            .AttachTargetEvent("CheckedChanged")
            .OfType <WeakPropertyBinding>()
            .SetSourcePropertySetter((data, o) => ((MainForm)data.Source.Source).UpdateWpfBinding((bool)o))
            .Activate();

            BindingEngine.SetPropertyBinding(this.winformTabControl, i => i.SelectedIndex, DataWarehouse.Instance, o => o.SelectedIndex)
            .SetMode(BindMode.TwoWay)
            .AttachTargetEvent("SelectedIndexChanged");

            BindingEngine.SetPropertyBinding(this.winformLabel, i => i.Text, DataWarehouse.Instance, o => o.SelectedIndex)
            .SetSourceBindMode(SourceMode.Property)
            .OfType <WeakPropertyBinding>()
            .SetTargetPropertySetter(this.UpdateViewModelLabelText);

            BindingEngine.SetPropertyBinding(this.wpfLabel, i => i.Text, DataWarehouse.Instance, o => o.SelectedIndex)
            .SetSourceBindMode(SourceMode.Property)
            .OfType <WeakPropertyBinding>()
            .SetTargetPropertySetter(this.UpdateViewModelLabelText);
        }
Ejemplo n.º 7
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            this.SetContentView(this.ViewLayoutResourceId);

            BindingEngine.Initialize(this);
        }
Ejemplo n.º 8
0
        public void Test_BindingEngine_CommandBinding_Expression()
        {
            var viewModel = new TestViewModel();
            var view      = new TestView();

            BindingEngine.SetCommandBinding(view, null, viewModel, i => i.AddAgeCommand)
            .Initialize <WeakCommandBinding>()
            .AttachTargetEvent("TestViewEvent");

            Assert.AreEqual(0, viewModel.Age);

            view.RaiseTestViewEvent();

            Assert.AreEqual(1, viewModel.Age);
        }
Ejemplo n.º 9
0
        public void Test_BindingEngine_ClearAllBinding()
        {
            var viewModel = new TestViewModel();
            var view      = new TestViewModel2();

            BindingEngine.SetPropertyBinding(view, "Name", viewModel, "Name")
            .SetMode(BindMode.TwoWay);

            viewModel.Name = Name1;
            Assert.AreEqual(view.Name, Name1);

            BindingEngine.ClearAllBindings();

            viewModel.Name = Name2;
            Assert.AreNotEqual(view.Name, Name2);
        }
Ejemplo n.º 10
0
        public void Test_BindingEngine_PropertyBinding_Expression()
        {
            var viewModel = new TestViewModel();
            var view      = new TestView();

            BindingEngine.SetPropertyBinding(view, o => o.Text1, viewModel, i => i.Name)
            .SetMode(BindMode.TwoWay)
            .AttachTargetEvent("TestViewEvent");

            viewModel.Name = Name1;

            Assert.AreEqual(view.Text1, Name1);

            view.Text1 = Name2;
            Assert.AreNotEqual(viewModel.Name, Name2);

            view.RaiseTestViewEvent();
            Assert.AreEqual(viewModel.Name, Name2);
        }
Ejemplo n.º 11
0
        public void Test_BindingEngine_GenericBinding()
        {
            var viewModel = new TestViewModel();
            var view      = new TestView();

            BindingEngine.SetBinding <WeakPropertyBinding>(view, "Text1", viewModel, "Name")
            .SetMode(BindMode.TwoWay)
            .AttachTargetEvent("TestViewEvent");

            viewModel.Name = Name1;

            Assert.AreEqual(view.Text1, Name1);

            view.Text1 = Name2;
            Assert.AreNotEqual(viewModel.Name, Name2);

            view.RaiseTestViewEvent();
            Assert.AreEqual(viewModel.Name, Name2);
        }
Ejemplo n.º 12
0
        public void Test_BindingEngine_MethodBinding_Expression()
        {
            var viewModel = new TestViewModel5();
            var button    = new Button();

            BindingEngine.SetMethodBinding(button, null, viewModel, o => o.TestViewModel)
            .Initialize <WeakMethodBinding>()
            .AttachSourceMethod("AddAge", null)
            .AttachSourceCanInvokeMethod("CanAddAge", null)
            .AttachTargetEvent("Click");

            viewModel.TestViewModel = new TestViewModel();

            Assert.AreEqual(0, viewModel.TestViewModel.Age);

            button.PerformClick();

            Assert.AreEqual(1, viewModel.TestViewModel.Age);
        }
        public void Test_WeakPropertyBinding_Index_Expression_Int()
        {
            var view      = new TestView();
            var viewModel = new TestViewModel();

            // 1. OneWay binding.
            BindingEngine.SetPropertyBinding(view, v => v.Text1, viewModel, vm => vm.TestViewModel2.TestViewModel3.TestViewModels[1].Name)
            .Initialize <WeakPropertyBinding>().OfType <WeakPropertyBinding>()
            .SetMode(BindMode.TwoWay)
            .AttachTargetEvent("TestViewEvent");

            var viewModel2 = new TestViewModel2();

            viewModel.TestViewModel2 = viewModel2;

            var viewModel3 = new TestViewModel3();

            viewModel2.TestViewModel3 = viewModel3;

            var testViewModels = new ObservableCollection <TestViewModel4>();

            viewModel3.TestViewModels = testViewModels;

            var t4  = new TestViewModel4();
            var t41 = new TestViewModel4();

            testViewModels.Add(t4);
            testViewModels.Add(t41);
            t41.Name = Name1;

            Assert.AreEqual(Name1, view.Text1);

            view.Text1 = Name2;
            view.RaiseTestViewEvent();
            Assert.AreEqual(Name2, t41.Name);

            var t42 = new TestViewModel4();

            testViewModels[1] = t42;
            Assert.AreEqual(null, view.Text1);
        }
Ejemplo n.º 14
0
        public void Test_BindingEngine_PropertyBinding()
        {
            var viewModel = new TestViewModel();
            var view      = new TestView();

            var binding = BindingEngine.SetPropertyBinding(view, "Text1", viewModel, "Name")
                          .SetMode(BindMode.TwoWay)
                          .AttachTargetEvent("TestViewEvent");

            Assert.AreEqual("Name", binding.SourceProperty);
            Assert.AreEqual("Text1", binding.TargetProperty);

            viewModel.Name = Name1;

            Assert.AreEqual(Name1, view.Text1);

            view.Text1 = Name2;
            Assert.AreNotEqual(Name2, viewModel.Name);

            view.RaiseTestViewEvent();
            Assert.AreEqual(Name2, viewModel.Name);
        }
 public Destination(Source src)
 {
     //Binder for Source no 1
     _binder = new BindingEngine <Destination>(this, src, 1);
 }
Ejemplo n.º 16
0
        private static void CompareReflectAndEmitBinding()
        {
            const int count = 2000;

            Console.ForegroundColor = ConsoleColor.Green;
            System.Console.WriteLine("\n=======  Compare Reflect and Emit Binding performance =======");


            var viewModels  = new TestViewModel[count];
            var viewModel2s = new TestViewModel2[count];

            DynamicEngine.SetBindingManager(new ReflectManager());

            for (int i = 0; i < count; i++)
            {
                var viewModel2 = new TestViewModel2();
                var viewModel  = new TestViewModel();
                viewModels[i]  = viewModel;
                viewModel2s[i] = viewModel2;

                BindingEngine.SetPropertyBinding(viewModel2, testView => testView.Age, viewModel, model => model.Age);
            }

            var sw = new Stopwatch();

            sw.Reset();
            sw.Start();

            for (int i = 0; i < count; i++)
            {
                viewModels[i].Age = i;
            }

            sw.Stop();

            Console.ForegroundColor = ConsoleColor.White;
            System.Console.WriteLine("Reflect manager time elapsed {0}", sw.ElapsedMilliseconds);

            DynamicEngine.SetBindingManager(new EmitManager());

            for (int i = 0; i < count; i++)
            {
                var viewModel2 = new TestViewModel2();
                var viewModel  = new TestViewModel();
                viewModels[i]  = viewModel;
                viewModel2s[i] = viewModel2;

                BindingEngine.SetPropertyBinding(viewModel2, testView => testView.Age, viewModel, model => model.Age);
            }

            sw = new Stopwatch();
            sw.Reset();
            sw.Start();

            for (int i = 0; i < count; i++)
            {
                viewModels[i].Age = i;
            }

            sw.Stop();

            Console.ForegroundColor = ConsoleColor.Yellow;
            System.Console.WriteLine("Emit manager time elapsed {0}", sw.ElapsedMilliseconds);
        }