Esempio n. 1
0
        public void BindWithFuncShouldWorkAsExtensionMethodSmokeTest()
        {
            var vm   = new PropertyBindViewModel();
            var view = new PropertyBindView()
            {
                ViewModel = vm
            };

            view.Bind(vm, x => x.JustADecimal, x => x.SomeTextBox.Text, d => d.ToString(), Decimal.Parse);
        }
Esempio n. 2
0
        public void ImplicitBindPlusTypeConversion()
        {
            var vm   = new PropertyBindViewModel();
            var view = new PropertyBindView()
            {
                ViewModel = vm
            };

            view.Bind(view.ViewModel, x => x.Property2);

            vm.Property2 = 42;
            Assert.Equal("42", view.Property2.Text);

            view.Property2.Text = "7";
            Assert.Equal(7, vm.Property2);
        }
Esempio n. 3
0
        public void ViewModelNullableToViewNullable()
        {
            var vm   = new PropertyBindViewModel();
            var view = new PropertyBindView()
            {
                ViewModel = vm
            };

            view.Bind(view.ViewModel, x => x.NullableDouble, x => x.FakeControl.NullableDouble);
            Assert.Equal(null, vm.NullableDouble);

            view.FakeControl.NullableDouble = 4.0;
            Assert.Equal(4.0, vm.NullableDouble);

            view.FakeControl.NullableDouble = null;
            Assert.Equal(null, vm.NullableDouble);

            view.FakeControl.NullableDouble = 0.0;
            Assert.Equal(0.0, vm.NullableDouble);
        }
Esempio n. 4
0
        public void TwoWayBindToSelectedItemOfItemsControl()
        {
            var vm   = new PropertyBindViewModel();
            var view = new PropertyBindView()
            {
                ViewModel = vm
            };

            view.FakeItemsControl.ItemsSource = new ObservableCollectionExtended <string>(new[] { "aaa", "bbb", "ccc" });

            view.Bind(view.ViewModel, x => x.Property1, x => x.FakeItemsControl.SelectedItem);

            Assert.Null(view.FakeItemsControl.SelectedItem);
            Assert.Null(vm.Property1);

            view.FakeItemsControl.SelectedItem = "aaa";
            Assert.Equal("aaa", vm.Property1);     // fail

            vm.Property1 = "bbb";
            Assert.Equal("bbb", view.FakeItemsControl.SelectedItem);
        }