Beispiel #1
0
        public void TestTwoWay()
        {
            var source = new BindableModel();
            var target = new BindableModel();

            var bindingA = new Binding("StringValue", target, "StringValue", Binding.BindingMode.TwoWay);
            var bindingB = new Binding("IntValue", target, "IntValue", Binding.BindingMode.TwoWay);

            // update source
            source.IntValue    = 1;
            source.StringValue = "A";

            // bind
            bindingA.Bind(source);
            bindingB.Bind(source);

            Assert.IsTrue(target.IntValue == 1);
            Assert.IsTrue(target.StringValue == "A");

            // update source
            source.IntValue    = 2;
            source.StringValue = "B";

            Assert.IsTrue(target.IntValue == 2);
            Assert.IsTrue(target.StringValue == "B");

            // update target
            target.IntValue    = 3;
            target.StringValue = "C";

            Assert.IsTrue(source.IntValue == 3);
            Assert.IsTrue(source.StringValue == "C");

            // unbind
            bindingA.Unbind();
            bindingB.Unbind();

            Assert.IsTrue(source.IntValue == 3);
            Assert.IsTrue(source.StringValue == "C");
            Assert.IsTrue(target.IntValue == 3);
            Assert.IsTrue(target.StringValue == "C");
        }
Beispiel #2
0
        public void TestOneWayToSource()
        {
            var source = new Model();
            var target = new BindableModel();

            var bindingA = new Binding("StringValue", target, "StringValue", Binding.BindingMode.OneWayToSource);
            var bindingB = new Binding("IntValue", target, "IntValue", Binding.BindingMode.OneWayToSource);

            // update target
            target.IntValue    = 1;
            target.StringValue = "A";

            // bind
            bindingA.Bind(source);
            bindingB.Bind(source);

            Assert.IsTrue(source.IntValue == 1);
            Assert.IsTrue(source.StringValue == "A");

            // update target
            target.IntValue    = 2;
            target.StringValue = "B";

            Assert.IsTrue(source.IntValue == 2);
            Assert.IsTrue(source.StringValue == "B");

            // unbind
            bindingA.Unbind();
            bindingB.Unbind();

            Assert.IsTrue(source.IntValue == 2);
            Assert.IsTrue(source.StringValue == "B");

            // update target
            target.IntValue    = 1;
            target.StringValue = "A";

            Assert.IsTrue(source.IntValue == 2);
            Assert.IsTrue(source.StringValue == "B");
        }