Ejemplo n.º 1
0
        public void SetUp()
        {
            _comboBox = new ComboBox();
            _comboBox.SetValue(UndoManager.UndoScopeNameProperty, "ScopeName");
            _fakeVm = new FakeVm();
            var selected = new Binding("SelectedEnum")
            {
                Source = _fakeVm,
                UpdateSourceTrigger = UpdateSourceTrigger.Explicit,
                NotifyOnSourceUpdated = true,
                NotifyOnTargetUpdated = true,
                Mode = BindingMode.TwoWay
            };
            BindingOperations.SetBinding(_comboBox, Selector.SelectedItemProperty, selected);

            var itemsSource = new Binding("EnumValues")
            {
                Source = _fakeVm,
                UpdateSourceTrigger = UpdateSourceTrigger.Explicit,
                NotifyOnSourceUpdated = true,
                NotifyOnTargetUpdated = true,
                Mode = BindingMode.OneWay
            };
            BindingOperations.SetBinding(_comboBox, ItemsControl.ItemsSourceProperty, itemsSource);
            _comboBox.DataContext = _fakeVm;
            _undoManager = UndoManager.GetUndoManager(_comboBox);
        }
Ejemplo n.º 2
0
 public void SetUp()
 {
     _textBox = new TextBox();
     _textBox.SetValue(UndoManager.UndoScopeNameProperty, "ScopeName");
     _fakeVm = new FakeVm();
     var binding = new Binding("Value")
     {
         Source = _fakeVm,
         UpdateSourceTrigger = UpdateSourceTrigger.Explicit,
         NotifyOnSourceUpdated = true,
         NotifyOnTargetUpdated = true,
         Mode = BindingMode.TwoWay
     };
     BindingOperations.SetBinding(_textBox, TextBox.TextProperty, binding);
     _textBox.DataContext = _fakeVm;
     _undoManager = UndoManager.GetUndoManager(_textBox);
 }
Ejemplo n.º 3
0
 public void UpdateTargetTest()
 {
     var textBox = new TextBox();
     var fakeVm = new FakeVm();
     var binding = new Binding("Value")
     {
         Source = fakeVm,
         UpdateSourceTrigger = UpdateSourceTrigger.Explicit,
         NotifyOnSourceUpdated = true,
         NotifyOnTargetUpdated = true,
         Mode = BindingMode.TwoWay
     };
     BindingOperations.SetBinding(textBox, TextBox.TextProperty, binding);
     textBox.DataContext = fakeVm;
     var bindingExpression = BindingOperations.GetBindingExpression(textBox, TextBox.TextProperty);
     bindingExpression.UpdateTarget();
     Assert.AreEqual("1", textBox.Text);
     fakeVm.Value = "2";
     Assert.AreEqual("1", textBox.Text);
     bindingExpression.UpdateTarget();
     Assert.AreEqual("2", textBox.Text);
 }